Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to open command prompt and auto send multiple commands as arguments on button click from windows form application in C#. Here instead of single command I want to send multiple commands one by one to same command prompt. Thanks in advance.
Posted
Updated 27-Aug-15 21:22pm
v5

1 solution

Assuming that your application supports reading the commands from the standard input, just use Process.StandardInput.WriteLine[^] to "send" new commands.

You won't be able to wait for exit though - that only occurs when the command processor exits, and you can't do anything useful with it after that.

If what you are trying to do is "queue up" windows commands to be executed one after the other, then consider writing a .BAT file and executing that instead. The batch file can check for success / fail and optionally continue or fail if you need it to.
 
Share this answer
 
Comments
Member 11848945 27-Aug-15 7:30am    
1) I tried with using Process.StandardInput.WriteLine[] but it doesn't work here to send command to cmd.exe.
2) Using .bat file make application use restricted as i need to specify specific path of .bat file if it changes then application will fail and even if use getpath in C# to auto search file path, but it won't be able to search where acess is denied.
OriginalGriff 27-Aug-15 7:48am    
Write the batch file anew each time with your application, and then execute it. When it completes, delete it. It doesn't have to have a "sensible" name - a GUID.BAT would do if you are worried about the file name conflicting.
OriginalGriff 27-Aug-15 8:32am    
Read what I said:
"Assuming that your application supports reading the commands from the standard input, just use Process.StandardInput.WriteLine[^] to "send" new commands."

If you want to queue them up, a batch file is your best solution.
OriginalGriff 27-Aug-15 10:29am    
You are kidding, right?
You know how to write files! :laugh:
Member 11848945 28-Aug-15 2:57am    
Thanks for suggestions.I created file using FileStream and added commands with streamwriter. Now code works fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900