- Home /
Trying to use System.Diagnostics.Process to access run a command
Hi, I'm trying to run a command through command prompt to have a program(phamtomjs) to run a javascript(chord_phamtomjs_test) and I'm able to do it in command prompt by getting to the directory by using cd commands and then once I'm in the directory with the application I enter this command "phantomjs chord_phantomjs_test.js" and the javascript executes. I'm trying to get this to work through unity and so far I've been able to open notepad with the following code.
function Start{
var strCmdTex:String;
strCmdText= "/C notepad";
System.Diagnostics.Process.Start("CMD.exe",strCmdText); //Start cmd process
}
I'm not sure where to go from here. Any help would be appriciated. Thanks
Answer by brilliancenp · Feb 27, 2014 at 07:47 PM
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.Filename = "Path\\To\\File\\phantomjs.exe";
process.StartInfo.Arguments = "chord_phantomjs_test.js";
//use to create no window when running cmd script
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
//if you want program to halt until script is finished
process.WaitForExit();
Your answer
Follow this Question
Related Questions
How do I tell command prompt to do a command after I open it through Unity? 1 Answer
How do I access command prompt from Unity 2 Answers
How to access .NET application from Unity via a Process? 2 Answers
Process.GetProcessesByName(string str); not working 2 Answers
Simple Android project shuts down when user presses the Recent Apps button 1 Answer