Command line in C#

  • Thread starter Thread starter Lubo¹ ©lapák
  • Start date Start date
L

Lubo¹ ©lapák

Hi,
i have a Win32 application in CSharp and i have to run command "net send
....." (these is a command for windows command-line) from this application,
but i don't know how can i run this command. How class can i use? Or how
command in CSharp exists for this issues?

Thanks a lot
Lubos
 
I have yet one question.

The command "net send" return a string value on next line, can i catch this
line and use it in my Win32 application?

If is it possible, how can i catch it?

Thanks
 
Lubo¹ ©lapák said:
I have yet one question.

The command "net send" return a string value on next line

No, that's output. That's not the same. Executables do have return values,
but that's something completely different.
, can i catch this
line and use it in my Win32 application?
If is it possible, how can i catch it?

Use the Process.StandardOutput property to read the process's output. You'll
find sample code in the documentation entry of that property.

Niki
 
e.g.

public class ProcessDataRetriever
{
public static string[] GetData(string cmd, string args)
{
using(Process p = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo(cmd, args);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
p.StartInfo = psi;
p.Start();
ArrayList a = new ArrayList(); string s;
while((s = p.StandardOutput.ReadLine()) != null) a.Add(s);
p.Close();
return (string[])a.ToArray(typeof(string));
}
}
}
 
Back
Top