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!
4 replies to this topic
#1
Posted 18 December 2010 - 04:57 PM
|
|
|
#2
Posted 22 December 2010 - 07:14 AM
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.. =)
I'm not a cygwin expert or anything though.. just a shot in the dark.. lets see what I hit.. =)
#3
Posted 22 December 2010 - 11:54 AM
Nope, no cygwin environment variables.
#4
Posted 22 December 2010 - 12:22 PM
From Cygwin documentation
I'd give it a try.
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).
#5
Posted 22 December 2010 - 12:23 PM
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
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


Sign In
Create Account

Back to top









