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

VulpesRank #55 · 29.2K reputationPosted Apr 12, 2011, 11:38 AM EDT
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 HobbsRank #107 · 20.5K reputationPosted Apr 11, 2011, 7:36 PM EDT
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?
Jay Webster58 reputationPosted Apr 11, 2011, 11:28 PM EDT
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
VulpesRank #55 · 29.2K reputationPosted Apr 12, 2011, 2:10 AM EDT
Jay Webster58 reputationPosted Apr 12, 2011, 3:39 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 12, 2011, 8:57 AM EDT
Jay Webster58 reputationPosted Apr 12, 2011, 9:16 AM EDT
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 :(
VulpesRank #55 · 29.2K reputationPosted Apr 12, 2011, 9:51 AM EDT
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 Webster58 reputationPosted Apr 12, 2011, 10:30 AM EDT
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?
VulpesRank #55 · 29.2K reputationPosted Apr 12, 2011, 11:22 AM EDT
So, if you find that file and examine it's contents, hopefully, it will show what you were expecting.
Jay Webster58 reputationPosted Apr 12, 2011, 11:29 AM EDT
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;
Jay Webster58 reputationPosted Apr 12, 2011, 12:08 PM EDT
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
Sam HobbsRank #107 · 20.5K reputationPosted Apr 12, 2011, 5:36 PM EDT