0

I am trying to write a PowerShell script to execute a command to open a java program. I am able to get the program to execute in CMD but not in PowerShell, thus why I want to go from PowerShell to CMD. Below is a list of the different lines that I have tried and none seem to work.

cmd.exe/c "Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-models.jar Test.TestCoreNLP"

cmd.exe/c "C:\Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-models.jar Test.TestCoreNLP"

& "C:\Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-models.jar Test.TestCoreNLP"

cmd.exe/c "C:\Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-models.jar Test.TestCoreNLP"

Start-Process '& "C:\Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-models.jar Test.TestCoreNLP"'

Invoke-Expression -Command:cmd.exe/C C:\Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-models.jar Test.TestCoreNLP

I have refered to this post in the community, Running CMD command in Powershell and https://social.technet.microsoft.com/Forums/office/en-US/7b398cea-0d29-4588-a6bc-ef793b51cc3c/run-a-dos-command-in-powershell?forum=winserverpowershell to formulate my attempted tries. Any help would be appreciated.

Thanks!

  • you can directly use: `& cmd /c "java.exe -version"`. whatever cmd you wish to run, wrap it inside the double quotes. If getting error then redirect that like `& cmd /c "java.exe -version 2>&1"` – Ranadip Dutta Jul 18 '17 at 15:29
  • What is that supposed to achieve: `Users\Forrest_Hunter\Documents\NetBeansProjects\ParsingEngine\src>java`? – Ansgar Wiechers Jul 18 '17 at 15:33
  • @AnsgarWiechers it is the path to where I want to run a java command. In turn the java command will execute a java program. – Forrest Hunter Jul 18 '17 at 15:37
  • @JamesC. thank you so much...although not what I was looking for, this question did have the answer to allow me to run my script in PS. Thanks again!!!! – Forrest Hunter Jul 18 '17 at 15:53
  • @ForrestHunter Doesn't work that way. Try `Set-Location "C:\some\folder"; & java -classpath ".;foo.jar;...;bar.jar" Test.TestCoreNLP` – Ansgar Wiechers Jul 18 '17 at 16:31
  • @AnsgarWiechers Thank you! I did need that line `Set_location: Some\folder` – Forrest Hunter Jul 18 '17 at 16:48

0 Answers0