Reputation: 13
I'm trying to launch libsvm's svm_scale on windows using the following code,
Process a = new Process();
a.StartInfo.FileName = ("C:\\Users\\Projects\\Documents\\libsvm-master\\windows\\svm-scale");
a.StartInfo.Arguments = ("-l -1 -u 1 -s range C:\\Users\\Projects\\Documents\\MyAttempts\\Attempt_3\\Final_Final.txt>C:\\Users\\Projects\\Documents\\MyAttempts\\Attempt_3\\Scale.scale");
a.Start();
but unfortunetely when running this code, it says "cannot open file C:\Users\Projects\Documents\MyAttempts\Attempt_3\Final_Final.txt>C:\Users\Projects\Documents\MyAttempts\Attempt_3\Scale.scale"
but when i type the same command on the command prompt it works fine and creates the Scale.scale file n the specifed destination. Please help me resolve this problem...... Thanx..
Upvotes: 1
Views: 336
Reputation: 13
finnaly I found a way to solve my error.
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var process = new Process { StartInfo = startInfo };
process.Start();
process.StandardInput.WriteLine(@"C:\\Users\\Batu\\Documents\\libsvm-master\\windows\\svm-scale -l -1 -u 1 -s range C:\\Users\\Batu\\Documents\\MyAttempts\\Attempt_3\\Final_Final.txt>C:\\Users\\Batu\\Documents\\MyAttempts\\Attempt_3\\Scale.scale");
//process.StandardInput.WriteLine(@"dir>c:\results2.txt");
process.StandardInput.WriteLine("exit");
process.WaitForExit();
Upvotes: 0
Reputation: 538
The problem is that the standard output redirection part (what goes after the '>' operator) you have in the arguments list is treated just like another argument.
That is because the output redirection is something the windows shell performs for you and your are using .net to launch the svm-scale program and not the shell.
If you wish to capture the standard output of the process you start, you should use the ProcessStartInfo.RedirectStandardOutput property combined with stream writing to a file. This has been answered in the past on stack overflow - for example here.
Upvotes: 1