Foo.cmd won't output lines in process (on website)

Viewed 23658

I've a problem understanding the in's and out's of the ProcessStartInfo class in .NET. I use this class for executing .exe programs like FFmpeg with no issues whatsoever.

But when I use ProcessStartInfo to start a .cmd program like a simple foo.cmd containing only @echo Hello world it doesn't output anything.

    ProcessStartInfo oInfo = new ProcessStartInfo(@"C:\Program Files (x86)\itms\foo.cmd")
    {
        UseShellExecute = false,
        RedirectStandardError = true,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    };

    using (Process p = new Process())
    {
        p.StartInfo = oInfo;
        p.OutputDataReceived += new DataReceivedEventHandler(transporter_OutputDataReceived);

        p.Start();

        p.BeginOutputReadLine();

        p.WaitForExit();
    }

private void transporter_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    Response.Write(e.Data + " - line<br/>");
}

I've seen a bunch of examples, where people use cmd.exe to start the .cmd program and I've tried this, but with no success. The program just keeps loading indefinitely.

    ProcessStartInfo oInfo = new ProcessStartInfo("cmd", "/c start foo.cmd")
    {
        UseShellExecute = false,
        RedirectStandardError = true,
        RedirectStandardOutput = true,
        CreateNoWindow = true,
        WorkingDirectory = @"C:\Program Files (x86)\itms"
    };

The foo.cmd program works and outputs successfully when using a command line tool in Windows and on Mac.

Could someone please demystify this for me.

Thanks

EDIT

The code behaves correctly when executed locally. The problem arises when I execute the code on our website. Either the program isn't allowed to execute or the output is somehow disabled.

Only cmd.exe is returning output ´"cmd", "/c dir"´ is e.g. returning information about the current folder content.

Could this actually be a permission issue?

4 Answers

What worked for me (instead of creating a new user for the Application Pool) was switching to Builtin Account 'Local System' (on IIS 8.5 on Windows Server 2012 R2).

Related