I have a UI application that is running in AppStream 2.0. I have a command button, that when pressed, makes an external call to a command line EXE.

I am using the ProcessStartInfo object to pass in the arguments.

            var startInfo = new ProcessStartInfo
            {
                FileName = @"My.exe",
                Arguments = '"' + jobNameToExecute + '"',
                WindowStyle = ProcessWindowStyle.Normal
            };

I then instantiate a Process, providing the ProcessStartInfo created above.

            var ExternalProcess = new Process {StartInfo = startInfo};
            ExternalProcess.Start();
            ExternalProcess.WaitForExit();

The process is erroring out with:

System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at

I can only assume that it isn't able to find the command line EXE. Do I need to provide a path for the EXE I'm calling? Can I use the path of the currently executing UI EXE?

Any insight would be appreciated.

1

There are 1 best solutions below

1
On

On Appstream, the application launches in such a way that the perceived "base/current" directory is not where the application exists. Because of this relative paths that should just work by taking on the base directory of the application will not work and you need to build the full path to the file.

Use something like AppDomain.CurrentDomain.BaseDirectory to get where the application is running from to build the path.

var startInfo = new ProcessStartInfo
        {
            FileName = $"{AppDomain.CurrentDomain.BaseDirectory}My.exe",
            Arguments = '"' + jobNameToExecute + '"',
            WindowStyle = ProcessWindowStyle.Normal
        };

or

var startInfo = new ProcessStartInfo
        {
            FileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"My.exe"),
            Arguments = '"' + jobNameToExecute + '"',
            WindowStyle = ProcessWindowStyle.Normal
        };

for example.