Jump to content

Problem with redirecting stdout/stderr

- - - - -

  • Please log in to reply
4 replies to this topic

#1
RexGloriose

RexGloriose

    Newbie

  • Members
  • Pip
  • 2 posts
Hi!

I would be really glad if somebody could help me solve this problem, becuase I got really stuck here. I am trying to launch an external process from a c# application (Winforms and .Net 4) and redirect the output.

My code works fine if I set FileName (see code below) to a one of my own console applications written in .Net, or several other applications, e.g. java.exe or ping.exe. I have however tried some of the applications shipped with cygwin, and a few of them, e.g. grep.exe or touch.exe, doesn't generate any output. If I run grep or touch in cmd.exe without parameters it outputs a usage/help text, but in my code below I don't get anything at all. In the cygwin package I have also tried ls.exe which works fine.

I find this grep problem really strange and annoying, so I would be really glad if anyone could come up with an explanation.

My code looks like this:

---------------------------------------------------------------------------------
outputTextbox.Text += "[Starting application]" + Environment.NewLine;

var p = new Process
{
StartInfo =
{
FileName = "ExeToRun",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};

p.Start();

var stdOut = p.StandardOutput.ReadToEnd();
var stdErr = p.StandardOutput.ReadToEnd();

stdOut = stdOut.Replace("\n", Environment.NewLine);
outputTextbox.Text += "[StdOut]" + Environment.NewLine + stdOut;

stdErr = stdErr.Replace("\n", Environment.NewLine);
outputTextbox.Text += "[StdErr]" + Environment.NewLine + stdErr;

p.WaitForExit();

outputTextbox.Text += "[Application finished]" + Environment.NewLine;
---------------------------------------------------------------------------------


Thanks!

#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
just for the sake of argument. do you have CYGWIN=tty set as an environment variable?

I'm not a cygwin expert or anything though.. just a shot in the dark.. lets see what I hit.. =)

#3
RexGloriose

RexGloriose

    Newbie

  • Members
  • Pip
  • 2 posts
Nope, no cygwin environment variables.

#4
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
From Cygwin documentation

Quote

(no)tty - if set, Cygwin enables extra support (i.e., termios) for UNIX-like ttys in the Windows console. It is not compatible with some Windows programs. Defaults to not set, in which case the tty is opened in text mode. Note that this has been changed such that ^D works as expected instead of ^Z, and is settable via stty. This option must be specified before starting a Cygwin shell and it cannot be changed in the shell. It should not be set when using other terminals (i.e., mintty or xterm).
I'd give it a try.

#5
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
to be clear, that would mean setting CYGWIN=tty in your environment, and a reboot may be needed

you would append cygwin parameters with a space, eg

CYGWIN=tty strip_title etc

documentation here
The CYGWIN environment variable




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users