简体   繁体   English

在Powershell脚本中使用cmd命令?

[英]Using a cmd command in powershell script?

I am trying to make a powershell script that automatically sets up this program and requires to use a cmd command to run do it. 我正在尝试制作一个Powershell脚本来自动设置该程序,并需要使用cmd命令来运行它。

I know that the cmd command work and I tried cmd.exe. 我知道cmd命令可以正常工作,并且尝试了cmd.exe。

cmd.exe /c "java -jar fitnesse-standalone.jar -p 9090"

Error Message: cmd.exe : The term 'cmd.exe' is not recognized 错误消息:cmd.exe:无法识别术语“ cmd.exe”

You can use start-process 您可以使用启动过程

Start-Process -FilePath "cmd.exe"  -ArgumentList '/c "java -jar fitnesse-standalone.jar -p 9090"'

The /c and everything following it is just part of the one set of parameters being passed to cmd. / c及其后的所有内容只是传递给cmd的一组参数的一部分。 If you want powershell to wait for the the Java app to close, add the -wait parameter. 如果希望powershell等待Java应用程序关闭,请添加-wait参数。

There's also no real need to use CMD at all in this case (since your giving it /c to exit immediately anyway), you can call java directly: 在这种情况下,也根本不需要使用CMD(因为您给/ c使其立即退出),因此可以直接调用java:

Start-Process -FilePath "java.exe"  -ArgumentList '-jar fitnesse-standalone.jar -p 9090'

and it should be the same. 它应该是相同的。

Note: you'll need Java in your path or the current working directory, and fitnesse-standalone.jar in the current directory for either of these to work. 注意:您需要在路径或当前工作目录中使用Java,并在当前目录中需要Fitnesse-standalone.jar才能使它们之一正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM