1
votes

I have a makefile and when I run this makefile on a windows console (cmd), it perfectly completes all the recipes.

However, when i run this script on a .NET process as shown below, it fails on a certain part:

     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();

The constant error is:

"Makefile:275: recipe for target 'list' failed"

the recipe "list" is like this:

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

The make ends just after the loop and does not execute sort.

Why is there a difference in behavior between cmd and C# process?

1
Without viewing makefile we can only guess reason of the error. Please, provide mcve. - Tsyvarev
@Tsyvarev, edited the question - fatihk
Result of the loop is a result of the last command executed within loop. It seems that sed command is failed for some reason. Probably, error message for that fails is written to stderr, but you redirect only stdout in your C# code. I am unsure, but difference between running make from cmd and C# (as a process) could be using different shells, which interprets make receipts. Or different environment for the shell (such as environment variables). - Tsyvarev
thanks, redirecting standard error worked like a charm - fatihk

1 Answers

0
votes

Thanks to Tsyvarev, I have found a solution. I redirected standard error in addition to the standard output:

featureExtractionProcess.StartInfo.RedirectStandardError = true;

and make scripts completes in a C# process without any problem