Home > Software design >  Process.start() not working or not giving output when the executable file is within the project
Process.start() not working or not giving output when the executable file is within the project

Time:11-07

 public void getDeviceinfo()
    {
        var proc = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "C:\\Users\\username\\Desktop\\repo\\project\\executable\\ideviceinfo.exe",
                Arguments = "-s",
                UseShellExecute = false,
                RedirectStandardOutput = true,
                CreateNoWindow = true
            }
        };

        proc.Start();
        while (!proc.StandardOutput.EndOfStream)
        {
            string line = proc.StandardOutput.ReadLine();
            Console.WriteLine(line);
        }

    }

I want to run a .exe file and get some output from it using C# project. When I'm having the .exe file within the project, it's executing but not giving any output. But If I keep the .exe outside of the project and if i give that location , then the executable file is executing and output is returned.

I tried keeping the executable in the debug folder also. But same issue.

I want to keep the executable file within the C# project and i want to execute it.

Any help please? Thanks.

CodePudding user response:

First, add the "WorkingDirectory" parameter to the ProcessStartInfo.

If that doesn't solve it then try moving it to a subfolder in your project. Maybe it is referencing a DLL (or some other resource) in your project rather than the system?

CodePudding user response:

The .exe file saved in the project cannot be exported. if your file path is correct. You can try to use "Process.Start(@" ")" object or "ProcessStartInfo" object to open

Code show as below:

  private void button1_Click(object sender, EventArgs e)
    {
        Process.Start(@"C:\test\bin\idea64.exe");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        //Public domain; no attribution required.
        ProcessStartInfo info = new ProcessStartInfo(@"C:\test\bin\idea64.exe");
        info.UseShellExecute = true;
        info.Verb = "runas";
        Process.Start(info);

    }

Run the project:

enter image description here

Hope it helps you.

  • Related