How to run a CMD.exe command from an ASP.NET application?

自闭症网瘾萝莉.ら 提交于 2019-12-11 12:44:08

问题


Here's my code:

string ex = "java -jar \"" + Settings.ClosureCompilerJarLocation + "\" --js \"" + C2runtimePath + "\" --js_output_file \"" + C2runtimeCompiledPath + "\" --language_in ECMASCRIPT5_STRICT --compilation_level ADVANCED_OPTIMIZATIONS --externs \"" + Settings.C2ExternsFolderLocation + "jquery-externs.js\" --externs \"" + Settings.C2ExternsFolderLocation + "c2-externs.js\"";
System.Diagnostics.Process.Start("CMD.exe", ex);

And an example of ex printed just before it executes:

java -jar "C:\inetpub\wwwroot\ScirraNew\static\ac\closure-compiler\compiler.jar" --js "C:\inetpub\wwwroot\arcade\games\46/c2runtime.js" --js_output_file "C:\inetpub\wwwroot\arcade\games\46/c2runtime_COMPILED.js" --language_in ECMASCRIPT5_STRICT --compilation_level ADVANCED_OPTIMIZATIONS --externs "C:\inetpub\wwwroot\ScirraNew\static\ac\templates\jquery-externs.js" --externs "C:\inetpub\wwwroot\ScirraNew\static\ac\templates\c2-externs.js"

  • It doesn't throw any errors and doesn't complete the command
  • If I copy + paste the command into cmd.exe myself it runs just fine

回答1:


You need to call WaitForExit() on the resultant Process instance.




回答2:


You should execute java.exe directly, with the desired arguments.

Passing cmd.exe a command line won't do anything.



来源:https://stackoverflow.com/questions/8235808/how-to-run-a-cmd-exe-command-from-an-asp-net-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!