I am trying to get Phantom.JS to run on a Windows computer and I have it working as a BAT file. I can open a console window, launch the BAT file and everything appears to work. That said, the output is too long for the console so I want to run the same thing inside of a .NET Console application. I have tried numerous things but I keep getting an error ‘phantom.js is not recognized as an internal or external command’
The BAT file itself consists of the following command:
phantomjs --config=config.json netsniff.js http://google.com
Here is my .NET code:
Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = "/C C:\\Test\\getpage.bat";
compiler.StartInfo.UseShellExecute = true;
compiler.Start();
Can somebody please help me figure out what I am doing wrong? Thank you!
Thank all of you for figuring this out for me. Here is a working solution:
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();
you specify the bat location as the filename not cmd.exe
although I don’t see the specific need for the bat file. you could just do something like:
the benefit of the second approach is you’re explicitly specifying the location of phantom js so you shouldn’t get the ‘phantom.js is not recognized as an internal or external command’ error.