question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Start-Process should support redirecting to variable names or stream objects

See original GitHub issue

Because there are many executables (mostly of linux origin) which use stderr to write status messages (in addition to errors), and rely purely on exit code to indicate whether there actually is an error or not …

As a PowerShell scripter, I need to be able to run an executable and both stream the output for sake of status updates and capture the (stderr) output so I can report on it properly if there is an actual error.

Start-Process doesn’t support this – it only captures to file, and if it does, it doesn’t output. Additionally, since output stream redirection is limited to redirecting to stdout or file, I cannot redirect error to verbose on CLI apps that consistently behave this way…

My current company has contrived more than one complicated wrapper around ProcessStartInfo and Diagnostics.Process to handle the output events and so on. In fact, it seems that every company I work with above a certain level of PowerShell maturity has their own custom Invoke-Process or other replacement for Start-Process to try and handle this.

Start-Process should allow capturing and also outputting

Start-Process should allow capturing (and reading input from) variables instead of just files

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveL-MSFTcommented, Oct 21, 2017

Personally, I think we should not enhance start-process and instead provide ways to solve interacting with processes natively. It seems that if we make the Variable: provider work like a file, this should solve some of your problems?

somecommand 2> variable:stderr 1> variable:stdout

Tee-Object doesn’t work with redirection, so need to think how to redirect while still outputting…

We should also allow redirecting one stream to another stream beyond stdout like:

somecommand 2>&3
0reactions
mklement0commented, Nov 12, 2017

P.S: Asking for the ability to capture stderr lines in a variable is the subject of #4332

Read more comments on GitHub >

github_iconTop Results From Across the Web

RedirectStandardOutput in Start-Process but still display it ...
Start-Process only allows you to redirect input and output streams from and to files, respectively. Using [Process]::Start to display output as ...
Read more >
With the Start-Process command, is there any way to get ...
Hey Redditors, I'm currently using the Start-Process command and am looking to extract the result of a Start-Process command, but isolate it in ......
Read more >
How to use Start-Process in PowerShell
Variables won't work. So what you can do to capture the output is: # Redirect the output to example-output.txt Start-Process -FilePath ...
Read more >
Impossible to catch exe output in PowerShell
You could redirect each stream one by one and store the output in a variable to see which one is being used. If...
Read more >
Creating a Child Process with Redirected Input and Output
The example in this topic demonstrates how to create a child process using the CreateProcess function from a console process.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found