-
Shell
Hello,
In VB you had the shell function that would allow you to run command line apps with args (from your app). In C#, I have not been able to find this. I did find an article on MSDN that demonstrated how to shell a DOS app with command line args. Here is my modified code:
Code:
public class LaunchEXE
{
internal static string Run(string exeName, string argsLine, int timeoutSeconds)
{
StreamReader outputStream = StreamReader.Null;
string output = "";
bool success = false;
try
{
Process newProcess = new Process();
newProcess.StartInfo.FileName = exeName;
newProcess.StartInfo.Arguments = argsLine;
newProcess.StartInfo.UseShellExecute = false;
newProcess.StartInfo.CreateNoWindow = true;
newProcess.StartInfo.RedirectStandardOutput = true;
newProcess.Start();
if (0 == timeoutSeconds)
{
outputStream = newProcess.StandardOutput;
output = outputStream.ReadToEnd();
newProcess.WaitForExit();
}
else
{
success = newProcess.WaitForExit(timeoutSeconds * 1000);
}
if (success)
{
outputStream = newProcess.StandardOutput;
output = outputStream.ReadToEnd();
}
else
{
output = "Timed out at " + timeoutSeconds + " seconds waiting for " + exeName + " to exit.";
}
}
catch(Exception e)
{
throw (new Exception("An error occurred running " + exeName + ".",e));
}
finally
{
outputStream.Close();
}
return "\t" + output;
}
}
And here is where I am calling the class:
Code:
string output;
output = LaunchEXE.Run("PowerOff.exe", "wol -ip XXX.XXX.XXX.XXX -subnet XXX.XXX.XXX.XXX -mac xxxxxxxxxxxx", 10);
Console.WriteLine (output);
The problem is that the app does not run correctly. It should send a wake on lan packet to the specified computer. I tested it using the command line and it works fine, but nothing happens through this app...any thought...?
-
Nevermind - I figured it out (syntax error in the args) - stupid me. Thanks.