Reputation:
I am using Visual Studio Clickones and try to execute (.appref-ms) application
and using RedirectStandardOutput
...
I have to use the option "Prefer 32-bit"
because I am using Access DB with connection string as Provider=Microsoft.Jet.OLEDB.4.0.
This is my execution code :
var p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Users\hed-b\Desktop\PulserTester.appref-ms")
{
RedirectStandardOutput = true,
UseShellExecute = false
};
p.Start();
reportNumber = p.StandardOutput.ReadToEnd();
p.WaitForExit();
This is the error I have got
System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'
Editing
By look here, I see that I can run it by cmd
as
var proc = Process.Start(@"cmd.exe ",@"/c C:\Users\hed-b\Desktop\PulserTester.appref-ms")
But How can I use RedirectStandardOutput this way?
Upvotes: 1
Views: 2187
Reputation: 1368
Looks like you're intending to start CMD and run a command, but your code just tries to run that command as an application.
Try something like this.
var p = new Process();
p.StartInfo = new ProcessStartInfo(@"cmd.exe")
{
RedirectStandardOutput = true,
UseShellExecute = false,
Arguments = "/c C:\Users\hed-b\Desktop\PulserTester.appref-ms"
};
p.Start();
reportNumber = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Using the blocking ReadToEnd
will pause your thread while that code runs and makes it harder to capture error output also - Have a look at this answer for a demonstration of a non blocking solution that captures both standard data and standard err : ProcessInfo and RedirectStandardOutput
Upvotes: 3