Cmd.exe question

Macs Bank

Client
Регистрация
25.04.2014
Сообщения
59
Благодарностей
3
Баллы
8
Hey guys,

This should be simple, but I'm having trouble.
I am using c# to run a specific command that I have stored in a variable.

I would like to get the response from the cmd run into a variable after it is executed.
for example, if I run a curl command in cmd.exe, how can I get the results returned into a variable to use in zenno?

Here's the code I have so far...

Код:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c "+ project.Variables["cmd"].Value;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
I'm not sure how to do this in C# but maybe it's better to call bat file which will execute exe + save data to textfile on harddrive?
 

Macs Bank

Client
Регистрация
25.04.2014
Сообщения
59
Благодарностей
3
Баллы
8
Thanks Rostonix -- I actually figured it out... or at least I got something working...
Код:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true; 
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
startInfo.WorkingDirectory = project.Directory;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c "+ project.Variables["cmd"].Value;
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
 
  • Спасибо
Реакции: Yann

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
great )
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)