Re: Recovering msgs from system() or fork() with Gtk+



On Sun, Apr 22, 2001 at 02:13:18PM +0000, Patrice St-Gelais wrote:
I want to be able to start any command / application that could be given
by the user from a gtk+ application:

(1)    The task must be independant from parent gtk+ app, so that the
user can continue the use the parent;

Sounds like fork() and exec().

(2)    I want to recover the error message, when the user gives a not
executable string, so that I can display it in a Gtk window.

man waitpid, or see the example in question 5.3 of the GTK+ FAQ.

Suppose the application is a simple text editor.  Something could be
done this way:

system("gedit mytext &");

Suppose now that the user makes a typo and gives "gedti".  Because
"system" launches a shell, the execution is successful (given the shell
is working).  It seems there is no way to recover the result of the
command inside the shell.  The only way for the user to know there was a
problem is to start the parent from an X console, where the child
displays its error message.

You can always redirect stdout and stderr. For an example, download the
DOSemu code from www.dosemu.org, and have a look at the function
run_unix_command() in src/base/misc/dos2linux.c.

I tried to use fork() followed by execlp()/execvp() in the child
process.  Fork() works when the child process exits with  _exit()
instead of exit().  Unfortunately, it doesn't work when I put a Gtk call
in the child process for displaying the error message.  The message
window displays, but hangs.  I've seen a message in this mailing list
saying it is not supposed to work.  I don't know the details.

See question 5.3 in the GTK+ FAQ.


Erik
[leaving userland again to hack arm-linux kernels]

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: J A K Mouw its tudelft nl
WWW: http://www-ict.its.tudelft.nl/~erik/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]