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

2019-08-13 13:44发布

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

2条回答
ゆ 、 Hurt°
2楼-- · 2019-08-13 13:57

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

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

查看更多
We Are One
3楼-- · 2019-08-13 14:06

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

查看更多
登录 后发表回答