0

I am currently working on translating a batch script into powershell. I have the following line:

"C:\Temp\User\Java\jre8\bin\java.exe" -cp "class.jar" classname url Output/create-%1_!cntr!.xml db2%1.xsl > "Output\result-%1_!cntr!.xml"

I need to write this in powershell, but am struggling on the syntax. I've tried putting the whole thing after a call operator with little success. I've tried Start-Process with everything after java.exe as an argumentlist, and I've also tried Start-Job -Scriptblock.

To be explicit about what I'm trying to do, I'm trying to call my java class class.jar with several parameters and then redirect the output to "Output\result-%1_!cntr!.xml"

2
  • Can it help ? stackoverflow.com/a/66345124/8017666 Commented Aug 26, 2021 at 8:10
  • @ShubhWIP I did consult that answer, yes, I couldn't get it to work, think the syntax is off. I'll have another go though. Commented Aug 26, 2021 at 8:45

1 Answer 1

0

Start-Process has a -RedirectStandardOutput key that you can use to specify output. You don't need to put it in -Argumentlist.

Final code:

$javaexee = "C:\Temp\User\Java\jre8\bin\java.exe"
$jarguments = "-cp javaclass url Output/create-$ending.xml db$btype.xsl > "
Start-Process $javaexee -ArgumentList $jarguments -RedirectStandardOutput "Output\result-$ending.xml" -PassThru -Wait
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.