我试图让 Phantom.JS 在 Windows 计算机上运行,并将它作为 BAT 文件工作。我可以打开一个控制台窗口,启动 BAT 文件,一切似乎都可以正常工作。也就是说,输出对于控制台来说太长了,所以我想在 .NET 控制台应用程序中运行相同的东西。我尝试了很多东西,但一直收到错误消息“phantom.js 未被识别为内部或外部命令”
BAT 文件本身包含以下命令:
phantomjs --config=config.json netsniff.js http://google.com
这是我的 .NET 代码:
Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = "/C C:\\Test\\getpage.bat";
compiler.StartInfo.UseShellExecute = true;
compiler.Start();
有人可以帮我弄清楚我做错了什么吗?谢谢!
感谢大家为我解决这个问题。这是一个有效的解决方案:
Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.WorkingDirectory = "C:\\Test\\";
compiler.StartInfo.Arguments = "/r getpage.bat";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
File.WriteAllText("C:\\Test\\pageoutput.txt",compiler.StandardOutput.ReadToEnd());
compiler.WaitForExit();