使用.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
满意答案
您需要将十六进制字符串正确转换为字节数组:
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)
SJCL库解密问题(SJCL library decryption issue)
用AES加密/解密(Android encryption / decryption using AES)
JS:存储在数据库(SJCL)后无法解密(JS: Decryption not possible after storing in database (SJCL))
PHP + Android XML加密/解密(PHP + Android XML Encryption/Decryption)
访问BlueStacks的应用程序(WhatsApp)数据库(Acessing BlueStacks' application (WhatsApp) database)
如何从android中的whatsapp将msgstore.db.crypt7转换为msgstore.db?(how to convert msgstore.db.crypt7 to msgstore.db from whatsapp in android?)
Android上的Whatsapp数据库解密(Whatsapp database decryption on Android)
Android - 加密和解密(Android - encryption and decryption)
解密错误JAVA(Android)(Error in Decryption JAVA(Android))
相关文章
更多Becoming a data scientist
ServletOutputStream cannot be resolved to a type
A Great List of Windows Tools
Solr: a custom Search RequestHandler
Create a Bootable MicroSD Card
Quitting an application - is that frowned upon?
Spring Data: a new perspective of data operations
Chapter 9 - Securing Your Application -- Professional ASP.NET MVC 1.0
Professional Android 4 Application Development
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!