简体   繁体   中英

Can't get output from console process

This code works well with ipconfig.exe, but i get nothing with my target app.

Process p = new Process();
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "miner.exe";
p.StartInfo.Arguments = command;
p.EnableRaisingEvents = true;

p.OutputDataReceived += OutputDataReceived;
p.ErrorDataReceived += ErrorDataReceived;

p.Start();
p.BeginOutputReadLine();
p.StandardInput.Close();

Can anybody tell what may be wrong and what can i do? Target app is written in c++ and i think uses printf for output. On forum i saw guy saying that he can't get this app work with pipes in linux.

Code look fine.

If process does not output anything to standard output you'd not be able to capture anything.

You can verify that it is program's behavior and not bug in you code by using existing output redirect on Windows or piping output to some other program Windows/*nix -

tool.exe > output.txt  
tool.exe | more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM