作为C#进程启动时,makefile配方失败

时间:2015-12-14 07:39:15

标签: c# process cmd makefile

我有一个makefile,当我在Windows控制台(cmd)上运行这个makefile时,它完美地完成了所有的配方。

但是,当我在.NET进程上运行此脚本时,如下所示,它在某个部分失败:

     Process featureExtractionProcess = new Process();

     featureExtractionProcess.StartInfo.FileName = "make.exe";

     featureExtractionProcess.StartInfo.Arguments = "all";
     featureExtractionProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     featureExtractionProcess.StartInfo.UseShellExecute = false;
     featureExtractionProcess.StartInfo.WorkingDirectory = _runLocation;
     featureExtractionProcess.StartInfo.RedirectStandardOutput = true;
     Logger.Debug("Starting feature extraction in " + _runLocation);
     featureExtractionProcess.Start();
     StreamReader sr = featureExtractionProcess.StandardOutput;
     string output = sr.ReadToEnd();

常数错误是:

“Makefile:275:目标'列表'的配方失败”

配方“列表”是这样的:

list:

    mkdir -p lists
    rm -f tmp
    for spkr in $(TRAINSPKR); do \
        for lab in labels/full/$${spkr}/*.lab; do \
            if [ -s $${lab} -a -s labels/mono/$${spkr}/`basename $${lab}` -a -s cmp/$${spkr}/`basename $${lab} .lab`.cmp ]; then \
                sed -e "s/.* //g" $${lab} >> tmp; \
            fi; \
        done; \
    done
    sort -u tmp > lists/full.list
    rm -f tmp

make在循环之后结束,不执行排序。

为什么cmd和C#进程之间的行为存在差异?

1 个答案:

答案 0 :(得分:0)

感谢Tsyvarev,我找到了解决方案。除了标准输出之外,我还重定向了标准错误:

featureExtractionProcess.StartInfo.RedirectStandardError = true;

并使脚本在C#进程中完成而没有任何问题