1

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?

1

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The tilde in terminal is expanded to the user's home. ~ in terminal is the same as $HOME. When the process is not run by your user or the ~ is not expanded, it won't work. I am glad to see you were able to help yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.