0

I have a powershell script that is calling a jar via the following code:

Start-Process java -ArgumentList '-jar', "$jarPath", "$csvPath"

However, the output from the jar is not coming through. I'm pretty sure its running successfully, but I'd like to be sure. How can I pass it through to the Powershell console?

6
  • Start-Process should do that by default. What does the Java code look like that supposedly generates output? Commented Aug 20, 2016 at 0:44
  • Maybe this helps? stackoverflow.com/questions/8761888/… Worked for me when I had a similar problem Commented Aug 20, 2016 at 11:25
  • @AnsgarWiechers I'm still not seeing anything being written using Start-Process, but I tried just running the java -jar "$jarPath" "$csvPath" straight and I'm now getting output to the console. Commented Aug 22, 2016 at 18:47
  • @whatever thank you, but I was looking to get the output as it was being generated, not once at the end. Commented Aug 22, 2016 at 18:48
  • 2
    Try running Start-Process with the parameter -NoNewWindow. Or simply use the call operator (see below). Commented Aug 22, 2016 at 19:31

2 Answers 2

3

Replace Start-Process with the call operator:

& java -jar $jarPath $csvPath
Sign up to request clarification or add additional context in comments.

Comments

1

This works fine for me:

$stdout = "C:\temp\stdout.txt"
Start-Process powershell -ArgumentList "echo 123" -RedirectStandardOutput $stdout -Wait
$output = Get-Content $stdout
echo $output
Remove-Item $stdout

Since I started Powershell process with command echo 123, it returned 123to stdout, so this value is saved to file. Swap Powershell with Java and it should be working as you expect. Remember, that you cannot redirect stdout directly to variable, you must do it via file.

1 Comment

I'm looking to hopefully have the output to be written as its generated, rather than once at the end. If that's not possible then this will definitely do the trick!

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.