1

I am having a very strange problem. I installed blat.exe by putting it in the c:/windows/system32 folder and I can run it perfectly from the command line.

When I run it programatically from C# Process.Start("cmd", "blat.exe blah blah") it returns the error

'blat.exe' is not recognized as an internal or external command, operable program or batch file.

I also tried giving the full path but it will just reply

c:/Windows/System32/blat.exe' is not recognized ...

Do you have any ideas / suggestions? Thanks a lot in advance.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
edd
  • 933
  • 2
  • 11
  • 24
  • 3
    You shouldn't ever be dumping random executables into windows system directories. I'm guessing that somewhere you're ending up running as a 32 bit process on a 64 bit machine and so hitting file system redirection. – Damien_The_Unbeliever Sep 08 '15 at 07:57
  • Are you saying that `Process.Start(@"C:\Windows\System32\blat.exe","args")` does _not_ work? – rbm Sep 08 '15 at 07:58
  • 4
    please dont write `blah blah`. what if the problem is inside blah blah? – M.kazem Akhgary Sep 08 '15 at 08:04

2 Answers2

0

You're not passing valid arguments to cmd. Here's some documentation.

Basically, if you want to start cmd with the argument that it should run blat.exe and then terminate, you will need to pass /C "blat.exe blah blah". Like so:

Process.Start("cmd", "/C \"blat.exe blah blah\"")

However, as someone has already stated in the comments, you might as well just run blat.exe directly.

0

I would say that Damien_The_Unbeliever was right. I simply moved blat from the windows directory to c:/blat/blat.exe and it works fine. For completeness and excuse me for the previous blah, blah, blah, the command that was failing is

        static void ExecuteCommandSync(object command)
    {
        try
        {
            System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo(@"C:/Windows/System32/blat.exe", "-server 127.0.0.1:1099 -subject Hello -to myname@gmail.com -body theBody -p gmailsmtp -from myname@gmail.com");
            System.Diagnostics.Process process;
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.RedirectStandardError = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            process = System.Diagnostics.Process.Start(procStartInfo);
            process.WaitForExit();
            var output = process.StandardOutput.ReadToEnd();
            var error = process.StandardError.ReadToEnd();
            var exitCode = process.ExitCode;
            Console.WriteLine(error);
            process.Close();
        }
        catch (Exception objException)
        {
            // to be logged
        }
    }

The variation with cmd.exe /c c:/Windows/System32/blat.exe was equally failing. Thanks very much for your help

edd
  • 933
  • 2
  • 11
  • 24