C#, run cmd, but stream the output, and not wait until its done running?
Code:
Code:
namespace Taynia_Updater
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.ProcessStartInfo sinf = new System.Diagnostics.ProcessStartInfo("cmd", "/c php taynia.php");
// The following commands are needed to redirect the standard output. This means that it will be redirected to the Process.StandardOutput StreamReader.
sinf.RedirectStandardOutput = true;
sinf.UseShellExecute = false;
// Do not create that ugly black window, please...
sinf.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = sinf;
p.Start(); // well, we should check the return value here...
// We can now capture the output into a string...
string res = p.StandardOutput.ReadToEnd();
// And do whatever we want with that.
Console.WriteLine(res);
Console.ReadLine();
}
}
}
What i'd like to do, but it won't work... compile errors, saying it wont convert from int to a string.
Code:
namespace Taynia_Updater
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.ProcessStartInfo sinf = new System.Diagnostics.ProcessStartInfo("cmd", "/c php taynia.php");
// The following commands are needed to redirect the standard output. This means that it will be redirected to the Process.StandardOutput StreamReader.
sinf.RedirectStandardOutput = true;
sinf.UseShellExecute = false;
// Do not create that ugly black window, please...
sinf.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = sinf;
p.Start(); // well, we should check the return value here...
while (Res = p.StandardOutput.Read())
{
Console.WriteLine(res);
}
// We can now capture the output into a string...
/*string res = p.StandardOutput.ReadToEnd();
// And do whatever we want with that.
Console.WriteLine(res);
*/
Console.ReadLine();
}
}
}
I'm not too familiar with C#, still learning. But this is something, I really would like to be able to do.
I don't want it to wait until it is done, i want it to stream the output, verbose mode or something along those lines. I mostly script php.
p.Start(); // well, we should check the return value here...
StreamReader myStreamReader = p.StandardOutput;
string myString = myStreamReader.ReadLine();
Console.WriteLine(myString);
// We can now capture the output into a string...
Hope this helps. I assume this is where your error was.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
p.Start(); // well, we should check the return value here...
StreamReader myStreamReader = p.StandardOutput;
string myString = myStreamReader.ReadLine();
Console.WriteLine(myString);
// We can now capture the output into a string...
Hope this helps. I assume this is where your error was.
Thanks bro, got me in the right direction, much appreciated, now to add error handling.