Question

So I have a chunk of code to call powercfg with the /requests option and get the result back from stdout.

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "powercfg";
p.StartInfo.Arguments = "/requests";
p.Start();

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

However when I run this code I get entirely different output than when I run the same command on the command line.

In the case of the code version I only get a load of "[DRIVER] ?" values back, but on the command line I get usually 2 or 3 properly formed responses.

I've run my code from the same command prompt window as the same user with the same environment, still no joy.

Any ideas ?

Was it helpful?

Solution 2

So the actual reason was that my application needed to be compiled for "Any CPU". Setting it to x86 or x64 caused issues with it loading the correct version of one of the dependent libraries.

OTHER TIPS

It may have something to do with the user context your application is running in, for example if you run your app as an administrator Process.Start will attempt to start the process in the same context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top