user8458667
user8458667

Reputation:

c# start console application in win forms

I'm trying to make launcher for my games and I like to add music player in background, but if I start the process it instantly fail's.

Code

private void btnStartMusic_Click(object sender, EventArgs e)
{
    ProcessStartInfo proc = new 
    ProcessStartInfo("MusicPlayer\\MemequickieMusicPlayer.exe");
    proc.CreateNoWindow = true;
    proc.WindowStyle = ProcessWindowStyle.Hidden;
    proc.RedirectStandardError = false;
    proc.RedirectStandardInput = false;
    proc.RedirectStandardOutput = false;
    proc.UseShellExecute = false;
    Process.Start(proc);
}

Any Help is appreciated.

Upvotes: 0

Views: 72

Answers (1)

Isma
Isma

Reputation: 15180

Try using the full path to the exe and setting the working directory; assuming the exe is in your executable folder:

string path = Path.Combine(Application.StartupPath, "MusicPlayer");

ProcessStartInfo proc = new 
    ProcessStartInfo(Path.Combine(path, "MemequickieMusicPlayer.exe")); 

proc.WorkingDirectory = path;

If the error persists and you want to debug the output, change:

proc.RedirectStandardOutput = true;

Create the process like this:

Process process = new Process(proc);
process.Start();

while (!process.StandardOutput.EndOfStream) {
    System.Diagnostics.Debug.Write(process.StandardOutput.ReadLine());
}

You should now see the output in your output window.

Upvotes: 1

Related Questions