简体   繁体   中英

How to show console when running a process?

I'm trying to launch a command in a console window / I'm using a gtk form/
So I've tried to launch it this way:

Process p = new Process ();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "bash";
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments ="/tmp/test.sh";
p.Start ();
p.WaitForExit ();

but it won't show any thing.
for those who only use windows, it's something like:

p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments =" c:\\test.bat";

I've tried to change UseShellExecute to true but the problem still exist..
Any Ideas??

Bash runs the script but if you want to see output, you need to run it in a terminal.

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "gnome-terminal"; // Replace with whichever terminal you want to use
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments ="-x bash /tmp/test.sh";
//p.StartInfo.Arguments ="-e \"bash -c /tmp/test.sh;bash\""; // Use this if you want the terminal window to stay open
p.Start();
p.WaitForExit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM