Reputation: 153
My program should start a Linux program and pass arguments to it. For debugging I print FileName and Arguments to the console.
private static void StartRecording(string channelName)
{
Console.WriteLine($"Starting recording of the channel {channelName}");
if (RecordingProcesses.ContainsKey(channelName)) return;
Process recordingProcess = new Process
{
StartInfo = new ProcessStartInfo
{
UseShellExecute = false,
FileName = RecorderPath,
Arguments = $"--appId {AppId} --channel {channelName} --uid {RecordingUid} --channelProfile 0 " +
$"--appliteDir {AppliteDir} --channelKey {GetToken(channelName)}",
}
};
recordingProcess.Exited += delegate { OnProcessExited(channelName); };
Console.WriteLine($"Starting process. FileName = {recordingProcess.StartInfo.FileName}, Arguments = {recordingProcess.StartInfo.Arguments}");
recordingProcess.Start();
RecordingProcesses.Add(channelName, recordingProcess);
}
That programs raises an error and says that I use wrong arguments. After that I close the program and try to launch that process manualy through the terminal by copy-pasting the FileName and then Arguments from the debug message to the terminal and the program runs ok. Why does that happen? How can I start the process from my program with the same result as when I start it from the terminal?
Upvotes: 1
Views: 295
Reputation: 153
I found the reason. It was because one of the argments contained a tilde. When running the program from terminal it was replaced by "/root". And when I used Process, it didn't replace tilde.
Upvotes: 3