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

使用.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();
}

相关问答

更多
  • 我通过使用以下内容来完成此操作: 根您的设备,并尝试此代码:: 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"); Data ...
  • 我设法解决了我的问题。 基本上这是两个/三个问题。 在我将它发送到执行数据库插入的php脚本之前,我需要对参数执行jquery“encodeURIComponent”,因为PHP提取函数剥离了加密字符串中的“+”。 第二个问题是必须使用PHP rawurldecode(而不是urldecode)将我的字符串恢复为带有“+”字符的前ajax格式,而不是“”。 第三个问题是使用jquerys“JSON.stringify”将它从javascript'对象'转换为sjcl.decrypt可以使用的字符串。 原来的 ...
  • 警告:此答案包含您不应使用的代码,因为它不安全(在ECB模式下使用SHA1PRNG进行密钥推导和使用AES) 相反,使用PBKDF2WithHmacSHA1进行密钥推导和AES在CBC或GCM模式(GCM提供隐私和完整性) 你可以使用这些功能: private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES") ...
  • 问题几乎肯定在于如何构建查询参数。 您需要使用encodeURIComponent对每个参数值进行编码,因为数据可能包含+等字符,除非正确编码,否则将转换为空格。 使用encodeURIComponent存储URL: var url = "action.php?action=r&n="+encodeURIComponent(name)+"&pw="+encodeURIComponent(pw_hashed)+"&encrypted="+encodeURIComponent(encrypted); 和您的检 ...
  • 以下代码可能会对您有所帮助。 使用这个你可以在PHP和Android之间加密/解密字符串。 Java部分: import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; ...
  • 这并不完全回答我的问题,但到目前为止,这是我能够获得的最多。 WhatsApp存储SD卡中所有会话的备份。 可以通过执行以下操作来访问它: 在BlueStacks上安装文件管理器,如Astro文件管理器 导航到sdcard/WhatsApp/Databases/ 消息历史记录备份存储在此处。 单击文件msgstore.db.crypt ,从出现的选项中选择Copy。 导航到/sdcard/bstfolder/bstSharedFolder/并粘贴该文件。 现在可以通过导航到C:/ProgramData/Bl ...
  • 正如Ashesh所说,你可以在XDA开发者网站上使用该工具: [TOOL] Whatsapp Xtract:备份消息提取器/数据库分析器/ Chat-Backup 或者,您可以手动执行以下操作: WhatsApp数据库在Android设备上以未加密的方式存储在此路径中: /data/data/com.whatsapp/databases/msgstore.db 数据库的备份也通常在以下位置加密存储在SD卡上: /sdcard/WhatsApp/Databases/msgstore.db.crypt7 加 ...
  • 您需要将十六进制字符串正确转换为字节数组: 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) ...
  • 最好的方法是使用非对称密钥对(RSA是最常见的),您在FTP站点上签署数据,在Android设备上保留私钥,呃,私钥和公钥。 您可以使用另一个密钥对进行加密/解密。 您可以使用您的签名字符串作为Android设备上的私有解密密钥的密码。 确保您的应用程序不容易受到填充oracle攻击(加密,然后签名或在解密失败时不通知对方)。 请注意,实现您自己的XML签名/验证或XML加密/解密版本可能非常困难(并且充满了至少与使用XML安全相关的库匹配的陷阱)。 我建议尝试将XML包装在CMS容器中。 对于其他用户,链 ...
  • Cipher.doFinal(byte[])返回byte[]而不是String 。 代码当前的方式是存储Object.toString()的返回值,对于byte[]来说,返回值不是很有意义,并且不显示它的内容。 如果要将字节数组存储为String,则需要先对其进行编码。 这样做的推荐方法是Base64,但是十六进制字符串也可以工作,但不会像Base64那样紧凑。 如果您只是想查看byte[]的内容以进行调试,可以使用Arrays.toString(byte[])来查看内容如何更改。 虽然即使是调试,但我认为 ...

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)