Hi,
I am trying to run a console app through console when running my winform app.
I want to run the following: abgx360 -ctxa --rgn 00FE0000 -- "F:\game.iso" > "C:\output.txt"
It should run through and produce output to output.txt. If I run it through on the command line directly, it works.
When I run it on my app it runs through but does not output to the file, I think the problem is with the > (Char)62.
Does > on a command line mean the same as (char)62? Should I be using something different?
I have been to the developer of the app and he is stumped, and since it works on the command line, I can only assume that it must be something wrong with my code.
I have the following code:
private void RunAbgx()
{
const string abgxPath = @"C:\Windows\SysWOW64\abgx360";
var outputPath = @"C:\output.txt";
var argument = " -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + " " + (Char)62 + " " + (Char)34 + outputPath + (Char)34;
// argument is: -ctxa --rgn 00FE0000 -- "F:\game.iso" > "C:\output.txt"
var pProcess = new Process
{
StartInfo =
{
FileName = abgxPath,
UseShellExecute = false,
Arguments = argument,
RedirectStandardOutput = false
}
};
pProcess.Start();
pProcess.WaitForExit();
}
Loading
VulpesPosted Apr 12, 2011, 3:38 PM
Also the second pair of (Char)34's is redundant.
*EDIT - just noticed that you haven't in fact because you'd removed it from the path. However, I'd get rid of the (Char)34's completely as they're not really needed and are just confusing the issue.
Sam HobbsPosted Apr 12, 2011, 9:36 PM
Jay WebsterPosted Apr 12, 2011, 4:08 PM
Final Code
private void RunAbgx()
{
const string abgxPath = @"C:\Windows\SysWOW64\";
var outputPath = @"D:\output.txt";
var argument = "/K " + abgxPath + "abgx360 -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + " > " + outputPath;
var pProcess = new Process
{
StartInfo =
{
FileName = "cmd.exe",
UseShellExecute = true,
WorkingDirectory = abgxPath,
Arguments = argument,
RedirectStandardOutput = false
}
};
pProcess.Start();
pProcess.WaitForExit();
}
Thanks for all your help Vulpes!! Wouldnt have got it without ya!
Jay
Jay WebsterPosted Apr 12, 2011, 3:29 PM
Okay, I have moved forward a bit, I think.
private void RunAbgx()
{
const string abgxPath = @"C:\Windows\SysWOW64\";
var outputPath = @"C:\output.txt";
var argument = " /K " + (Char)34 + abgxPath + "abgx360 -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + (Char)34; // Works but no text output.
//var argument = " /K " + (Char)34 + abgxPath + "abgx360 -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + (Char)34 + " > " + outputPath; // Access Denied message
var pProcess = new Process
{
StartInfo =
{
FileName = "cmd.exe",
UseShellExecute = false,
WorkingDirectory = abgxPath,
Arguments = argument,
RedirectStandardOutput = false
}
};
pProcess.Start();
pProcess.WaitForExit();
}
This works fine, although doesnt output the text, which I require.
var argument = " /K " + (Char)34 + abgxPath + "abgx360 -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + (Char)34;
When I change it to this, I get an Access Denied message..
var argument = " /K " + (Char)34 + abgxPath + "abgx360 -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + (Char)34 + " > " + outputPath;
VulpesPosted Apr 12, 2011, 3:22 PM
So, if you find that file and examine it's contents, hopefully, it will show what you were expecting.
Jay WebsterPosted Apr 12, 2011, 2:30 PM
I ran your exact code and all I get is this when run.
It does not seem to be using the argument at all.
Any ideas?
VulpesPosted Apr 12, 2011, 1:51 PM
I'd try it instead exactly as per my suggestion. It shouldn't be necessary to place txtPath.Text within quotes unless it contains embedded spaces. The same remark applies to outputPath.
Jay WebsterPosted Apr 12, 2011, 1:16 PM
private void RunAbgx()
{
const string abgxPath = @"C:\Windows\SysWOW64\";
var outputPath = @"C:\output.txt";
var argument = "abgx360 -ctxa --rgn 00FE0000 -- " + (Char)34 + txtPath.Text + (Char)34 + " > " + (Char)34 + outputPath + (Char)34;
Console.WriteLine(argument);
var pProcess = new Process
{
StartInfo =
{
FileName = "cmd.exe",
UseShellExecute = false,
WorkingDirectory = abgxPath,
Arguments = argument,
RedirectStandardOutput = false
}
};
pProcess.Start();
pProcess.WaitForExit();
}
It just sits at C:\Windows\SysWOW64\ and doesnt run abgx360 though :(
Sam HobbsPosted Apr 12, 2011, 12:57 PM
Jay WebsterPosted Apr 12, 2011, 7:39 AM
VulpesPosted Apr 12, 2011, 6:10 AM
Jay WebsterPosted Apr 12, 2011, 3:28 AM
Thanks for your reply.
Solution 1
I have already tried to do the redirection within the program, although when I did it ABGX360 wouldnt run and all I get is a blank console screen. I will post the code I tried later to see if I am perhaps doing it wrong, I would prefer to do it this way.
Solution 2
Do you mean I should try this?
StartInfo =
{
FileName = abgxPath + argument,
UseShellExecute = false,
RedirectStandardOutput = false
}
I am at work right now so I cant test it yet, but I will when I get home.
Jay
Sam HobbsPosted Apr 11, 2011, 11:36 PM
The solution I suggest is that you do the redirection in your program. In other words, use the Process.StandardOutput Property to provide a stream that your program reads from. Look for articles and documentation about that.
Alternatively, execute the command processor and specify a command line that is the same as if you were executing the program in a command prompt window with the ">" to redirect the output. The reason that would work and why redirection does not work without the command processor is because it is the command processor that processes the redirection operators (such as ">") in the command line. Does that explain what is happening?