1

我正在使用以下代码将 cmd 调用的输出记录到文件中,但它有时无法正常工作。

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
//startInfo.Arguments = "/C dir C:\\  >c:\\temp\\dir.txt";
startInfo.Arguments = "/C \"C:\\Program Files\\Geth\\geth.exe\" --exec \"web3.eth.getBalance(web3.eth.accounts[0]);\" attach >c:\\temp\\out.txt";
process.StartInfo = startInfo;
process.Start();

简单的目录工作正常。使用没有 --exec 的 Ethereum geth.exe 可以正常工作。但是,一旦我包含 --exec 参数,输出就是空白的。如果在 cmd.exe 中手动调用,这两个命令都可以正常工作并产生输出。

"C:\Program Files\Geth\geth.exe" 附加 >c:\temp\out.txt

"C:\Program Files\Geth\geth.exe" --exec "web3.eth.getBalance(web3.eth.accounts[0]);" 附加 >c:\temp\out.txt

4

1 回答 1

0

我看到您找到了解决方法,但对于其他人:

process.Start();
process.WaitForExit();

您必须等待进程退出。

于 2018-10-09T17:12:35.800 回答