![]() Send a directory command and an exit command to the shell Process.ErrorDataReceived += ProcessErrorDataHandler Process.OutputDataReceived += ProcessOutputDataHandler Runs the specified command and exits the shell immediately. Redirects the standard input so that commands can be sent to the shell. = Path.Combine(Environment.SystemDirectory, "cmd.exe") If you still have a problem, what do you get if you just try = ""python.exe -c ""import sys print 'Test.' """"" ?Īlso, the code below demonstrates most of the necessary concepts for shell communication: public static void Main() See Process.BeginOutputReadLine Method and Process.BeginErrorReadLine Method for more details. The process is similar for the error ouput as well. Immediately after calling Start, call (). Instead of trying to hook the StreamReader's BaseStream, hook the OutputDataReceived event with += ProcessOutputHandler before you call Start where ProcessOutputHandler has a signature like public static void ProcessOutputHandler(object sendingProcess, DataReceivedEventArgs outLine). To answer your Edit 3 problem, you're probably not correctly hooking into the outputs. See Cmd and ProcessStartInfo.Arguments Property. If info.Arguments = with perl.exe doesn't work, you may find it necessary to launch them inside cmd.exe to get normal behavior out of them, i.e. ![]() The /c option tells cmd.exe to execute the relevant commands and then quit.Īdditionally, interpreters like python and perl sometimes have weird behaviors when launched directly from ProcessStartInfo. Your other issue with never returning is that cmd.exe opens in interactive mode by default when it is executed without any, or proper, arguments. If you have multiple commands that you want it to perform you will either have to put the commands in a batch file and execute that or enclose them in quotes and separate them with &, i.e. If you want the cmd.exe shell to execute a series of command and then quit you will have to provide the /c argument. The string in info.Arguments is the arguments provided to the program on the command line. You cannot send commands to a shell this way. Any suggestions why that might be happening ? but when i access the python interpreter, the interpreter's output is still not visible in my tool. Įdit 3 : So I managed to do move a wee bit forward following Jamie's suggestions. The command line tools like python,perl are not working. I need to use the same method for other normal cmd line commands as well.It would be nice, if somebody can point what i am doing wrong with the code that I have or what I must do, in order to achieve the intended functionality.ĮDIT 2 : The normal cmd commands are working perfectly. BeginRead(errorBuffer, 0, errorBuffer.Length, new AsyncCallback(this.OnErrorInput), this.shellProcess) BeginRead(outputBuffer, 0, outputBuffer.Length, new AsyncCallback(this.OnOutputInput), this.shellProcess) If (!string.IsNullOrEmpty(startingDirectory) & System.IO.Directory.Exists(startingDirectory)) ProcessStartInfo info = new ProcessStartInfo("cmd.exe") I am also attaching the code that I currently have. It would be easier for you guys to understand what I am trying to say. ![]() it simply keeps on waiting.įor your kind consideration I am also linking the video here. From the python folder I try to launch python.exe but at this point, my editor does not do anything. It seems as if my application is waiting for something (instead of displaying the result)įrom my tool I navigate to the python folder. ![]() Everything works fine but the Use case below fails to do anything. For one of my implementations I am working on a tool that is supposed to send/retrieve commands/results to/from the cmd window. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |