Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting bash.exe process using .Net/Powershell with UseShellExecute=false results in "Error: 0x80070057" #461

Closed
kswoll opened this issue Jun 1, 2016 · 3 comments

Comments

@kswoll
Copy link

kswoll commented Jun 1, 2016

Same error as for Issue 7 and Issue 110 except that in my scenario I'm not running bash through the CMD prompt. Originally I was attempting to start bash in a C# program and was trying to capture standard out, which requires that UseShellExecute be false. (that's very important -- if it's true, everything works, but you can't capture standard output) Since the same problem arises in a powershell script, I'll post it here:

$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "bash.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
Write-Host "exit code: " + $p.ExitCode

The output of that was:

PS C:\Users\kirkw> Write-Host "stdout: $stdout"
tdout: E r r o r : 0 x 8 0 0 7 0 0 5 7
PS C:\Users\kirkw> Write-Host "stderr: $stderr"
stderr:
PS C:\Users\kirkw> Write-Host "exit code: " + $p.ExitCode
exit code: + -1

I'm trying to execute a bash program from a C# program (or powershell script) and capture the standard output. This seems unsupported currently. Is this expected behavior? Is there a workaround? Currently the only way I can get this to work is to set UseShellExecute to true, and redirect the output to a temporary file that my C# program subsequently reads. This is less desirable as it makes tracking the output in realtime onerous.

@stehufntdev
Copy link
Collaborator

Thanks for reporting the issue, yes this is expected. #2 has more details if you are interested:

"We have a known limitation where we only support the console for stdin and stdout. If either of those are not a console then we will fail"

I'm going to close this out as a duplicate so we can track the issue in that post.

@kswoll
Copy link
Author

kswoll commented Jun 1, 2016

@stehufntdev oh, apologies for missing the dup. But thanks for steering me in the right direction!

@stehufntdev
Copy link
Collaborator

Not a problem at all, thanks for the feedback and for trying out WSL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants