I ran into a peculiar situation with the following code sample that I don't understand. Below is a complete program that starts a process of youtube-dl.exe
that downloads a youtube video. Both youtube-dl
and ffmpeg
binaries are present in the same directory as Task_Starter.exe
(my program).
const string destinationFolder = @"C:\Users\Home\source\repos\Task Starter\Task Starter\bin\Release";
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = "youtube-dl.exe";
process.StartInfo.Arguments = "https://www.youtube.com/watch?v=K4TOrB7at0Y";
process.StartInfo.Arguments += (" -o " + "\"" + destinationFolder + "/%(title)s-%(id)s.%(ext)s" +
"\" --restrict-filenames --no-mtime --ffmpeg-location ffmpeg.exe");
Console.WriteLine("arguments: " + process.StartInfo.Arguments);
process.Start();
//Process.Start("notepad.exe"); // <--What is going on here?
Task.Run(() => {
while (!process.StandardOutput.EndOfStream) {
string line = process.StandardOutput.ReadLine();
Console.WriteLine(line);
}
});
Console.ReadLine();
The strange part about it is that this code does not start the process when being run inside Rider
but does exactly what it should when launching Task_Starter.exe
in cmd
.
It also does not start the video download when I run it via a task scheduler manually pressing Run
button in Task Scheduler.
schtasks /Create /SC ONLOGON /TN "Youtube DL Starter" /RL HIGHEST /TR "'C:\Users\Home\source\repos\Task Starter\Task Starter\bin\Release\Task_Starter.exe'"
But it does start correctly if I just add Process.Start("notepad.exe");
anywhere below process.Start();
If I add that, then it successfully launches youtube-dl.exe
, downloads the video both when executed within Rider
and if executed via task.
I hope you can point out what I am missing here. How launching a completely separated process of notepad.exe
influenced what other parts of my code do?
Windows 10 Pro, Version 10.0.18363 Build 18363
.NETFramework v4.6.1