使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)

我创建了一个可以读取命令参数的控制台应用程序(使用Visual Studio 2010)。

当我调试时,我解析了一些在Project-> [project name] Properties ... - > Debug - > Command line arguments中设置的测试参数:

它读取:“parametername1 | parametervalue1”“parametername2 | parametervalue2”“parametername3 | parametervalue3”

我使用下面的代码来读取参数:

for (Int16 argumentsCount = 0; argumentsCount < args.Length; argumentsCount++)
{
    String[] parameterItem = args[argumentsCount].Split('|');
    String parameterName = parameterItem[0].ToString();
    String parameterValue = parameterItem[1].ToString();
    /*code continues*/

}

当我在调试模式下运行该应用程序它工作得很好,并读取所有参数。

然后我发布了应用程序到服务器,并确保它安装了正确的权限(为了演示的目的,可以说它在C:\ MyApp上,并且Complied代码驻留在MyApp.application中

然后我创建了一个执行应用程序的批处理脚本。 * .BAT包含以下命令:

"C:\MyApp\MyApp.application" "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"

当我运行批处理时,这种作为应用程序的方式执行...但是...我的应用程序没有收到任何参数。 我知道这一点,因为我重新编译并发布了一些代码,以读取正在接收的参数数量:

Console.Write("Arguments " + args.Length.ToString());

并显示参数:0

有人可以告诉我如何编写我的批处理脚本来运行应用程序并解析我的参数/命令行参数。


I've created a console app (using Visual Studio 2010) which can read command arguments.

When I debug, I parse some test parameters which are set in Project-> [project name] Properties... -> Debug -> Command line arguments:

It reads: "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"

I used the following code to read the parameters:

for (Int16 argumentsCount = 0; argumentsCount < args.Length; argumentsCount++)
{
    String[] parameterItem = args[argumentsCount].Split('|');
    String parameterName = parameterItem[0].ToString();
    String parameterValue = parameterItem[1].ToString();
    /*code continues*/

}

When I run in debug mode the app it works just fine and all parameters are read.

I then published the app to a server and ensured it was installed with the correct permissions (for the purposes of demonstration lets say it's on C:\MyApp and the Complied code resides in MyApp.application

I then created a batch script that executes the app. The *.BAT contains the following command:

"C:\MyApp\MyApp.application" "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"

This kind of works as the application executes when I run the batch... However... none of my parameters are being received by my app. I know this because I recompiled and published with some code to read how many parameters are being received with:

Console.Write("Arguments " + args.Length.ToString());

and that shows Arguments: 0

Can someone please tell me how to write my batch script to run the app and parse my parameters/command line arguments.


原文:https://stackoverflow.com/questions/6274835
2024-04-24 20:04

满意答案

您需要将十六进制字符串正确转换为字节数组:

private static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

public void decryptDatabase(String k, String iv) throws InvalidKeyException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException, NoSuchPaddingException, IOException {

    File extStore = Environment.getExternalStorageDirectory();
    FileInputStream fis = new FileInputStream(extStore
            + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr");
    FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db");

    SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(k), "AES");
    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
    cipher.init(Cipher.DECRYPT_MODE, sks,
            new IvParameterSpec(hexStringToByteArray(iv)));
    CipherInputStream cis = new CipherInputStream(fis, cipher);
    int b;
    byte[] d = new byte[8];
    while ((b = cis.read(d)) != -1) {
        fos.write(d, 0, b);
    }
    fos.flush();
    fos.close();
    cis.close();
}

You need to convert the hex strings to byte arrays properly:

private static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

public void decryptDatabase(String k, String iv) throws InvalidKeyException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException, NoSuchPaddingException, IOException {

    File extStore = Environment.getExternalStorageDirectory();
    FileInputStream fis = new FileInputStream(extStore
            + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr");
    FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db");

    SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(k), "AES");
    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
    cipher.init(Cipher.DECRYPT_MODE, sks,
            new IvParameterSpec(hexStringToByteArray(iv)));
    CipherInputStream cis = new CipherInputStream(fis, cipher);
    int b;
    byte[] d = new byte[8];
    while ((b = cis.read(d)) != -1) {
        fos.write(d, 0, b);
    }
    fos.flush();
    fos.close();
    cis.close();
}

相关问答

更多

Android阅读WhatsApp数据(Android Read WhatsApp Data)

我通过使用以下内容来完成此操作: 根您的设备,并尝试此代码:: public void copyDbToSdcard() { try { String comando = "cp -r /data/data/com.whatsapp/databases/msgstore.db /sdcard/My_Custom_Folder/"; Process suProcess = Runtime.getRuntime().exec("su"); ...

SJCL库解密问题(SJCL library decryption issue)

我设法解决了我的问题。 基本上这是两个/三个问题。 在我将它发送到执行数据库插入的php脚本之前,我需要对参数执行jquery“encodeURIComponent”,因为PHP提取函数剥离了加密字符串中的“+”。 第二个问题是必须使用PHP rawurldecode(而不是urldecode)将我的字符串恢复为带有“+”字符的前ajax格式,而不是“”。 第三个问题是使用jquerys“JSON.stringify”将它从javascript'对象'转换为sjcl.decrypt可以使用的字符串...

用AES加密/解密(Android encryption / decryption using AES)

警告:此答案包含您不应使用的代码,因为它不安全(在ECB模式下使用SHA1PRNG进行密钥推导和使用AES) 相反,使用PBKDF2WithHmacSHA1进行密钥推导和AES在CBC或GCM模式(GCM提供隐私和完整性) 你可以使用这些功能: private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "...

JS:存储在数据库(SJCL)后无法解密(JS: Decryption not possible after storing in database (SJCL))

问题几乎肯定在于如何构建查询参数。 您需要使用encodeURIComponent对每个参数值进行编码,因为数据可能包含+等字符,除非正确编码,否则将转换为空格。 使用encodeURIComponent存储URL: var url = "action.php?action=r&n="+encodeURIComponent(name)+"&pw="+encodeURIComponent(pw_hashed)+"&encrypted="+encodeURIComponent(encrypted); ...

PHP + Android XML加密/解密(PHP + Android XML Encryption/Decryption)

以下代码可能会对您有所帮助。 使用这个你可以在PHP和Android之间加密/解密字符串。 Java部分: import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeyS...

访问BlueStacks的应用程序(WhatsApp)数据库(Acessing BlueStacks' application (WhatsApp) database)

这并不完全回答我的问题,但到目前为止,这是我能够获得的最多。 WhatsApp存储SD卡中所有会话的备份。 可以通过执行以下操作来访问它: 在BlueStacks上安装文件管理器,如Astro文件管理器 导航到sdcard/WhatsApp/Databases/ 消息历史记录备份存储在此处。 单击文件msgstore.db.crypt ,从出现的选项中选择Copy。 导航到/sdcard/bstfolder/bstSharedFolder/并粘贴该文件。 现在可以通过导航到C:/ProgramDa...

如何从android中的whatsapp将msgstore.db.crypt7转换为msgstore.db?(how to convert msgstore.db.crypt7 to msgstore.db from whatsapp in android?)

正如Ashesh所说,你可以在XDA开发者网站上使用该工具: [TOOL] Whatsapp Xtract:备份消息提取器/数据库分析器/ Chat-Backup 或者,您可以手动执行以下操作: WhatsApp数据库在Android设备上以未加密的方式存储在此路径中: /data/data/com.whatsapp/databases/msgstore.db 数据库的备份也通常在以下位置加密存储在SD卡上: /sdcard/WhatsApp/Databases/msgstore.db.cryp...

Android上的Whatsapp数据库解密(Whatsapp database decryption on Android)

您需要将十六进制字符串正确转换为字节数组: private static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) ...

Android - 加密和解密(Android - encryption and decryption)

最好的方法是使用非对称密钥对(RSA是最常见的),您在FTP站点上签署数据,在Android设备上保留私钥,呃,私钥和公钥。 您可以使用另一个密钥对进行加密/解密。 您可以使用您的签名字符串作为Android设备上的私有解密密钥的密码。 确保您的应用程序不容易受到填充oracle攻击(加密,然后签名或在解密失败时不通知对方)。 请注意,实现您自己的XML签名/验证或XML加密/解密版本可能非常困难(并且充满了至少与使用XML安全相关的库匹配的陷阱)。 我建议尝试将XML包装在CMS容器中。 对于其...

解密错误JAVA(Android)(Error in Decryption JAVA(Android))

Cipher.doFinal(byte[])返回byte[]而不是String 。 代码当前的方式是存储Object.toString()的返回值,对于byte[]来说,返回值不是很有意义,并且不显示它的内容。 如果要将字节数组存储为String,则需要先对其进行编码。 这样做的推荐方法是Base64,但是十六进制字符串也可以工作,但不会像Base64那样紧凑。 如果您只是想查看byte[]的内容以进行调试,可以使用Arrays.toString(byte[])来查看内容如何更改。 虽然即使是调试...

相关文章

更多

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

ServletOutputStream cannot be resolved to a type

在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec ...

A Great List of Windows Tools

Windowsis an extremely effective and a an efficient ...

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

Create a Bootable MicroSD Card

http://gumstix.org/create-a-bootable-microsd-card.h ...

Quitting an application - is that frowned upon?

在Quitting an application - is that frowned upon?中,很 ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

Chapter 9 - Securing Your Application -- Professional ASP.NET MVC 1.0

Overview Let's face it: security isn't sexy. Most ...

Professional Android 4 Application Development

Developers, build mobile Android apps using Android ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本