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"

Yvain
  • 261
  • 2
  • 11
  • Can it help ? https://stackoverflow.com/a/66345124/8017666 – SRJ Aug 26 '21 at 08: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. – Yvain Aug 26 '21 at 08:45

1 Answers1

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
Yvain
  • 261
  • 2
  • 11