[Glade-users] newbie: making system calls from GUI
- From: michele floris cern ch (Michele Floris)
- Subject: [Glade-users] newbie: making system calls from GUI
- Date: Thu, 06 Feb 2003 12:18:47 +0100
Hi,
I use something like this:
///////////////////////////////////////////////////////////////////////
int execute_command(char command[], char * str, int number_of_char){
// This function executes "command" and put its output in the vector
pointed by str,
// up to a number of characters equal to number_of_char, one line every
number_of_char characters
.
// Returns the number of line read
FILE * stream ;
int i = 0;
if ( (stream = popen(command,"r")) == NULL){
perror("Error, while executing");
exit(1);
}
while ( fgets(str + (i*number_of_char) , number_of_char, stream ) !=
NULL) i++;
pclose(stream);
return i;
}
////////////////////////////////////////////////////////////////////
This funztions opens a pipe to the command given as an argument (for
example "mozilla") and gets the standard output.
If you also want to get the standart error using this functions you
should redirect it to the standard output (that is command should be
something like "mozilla 2>&1"). You'll probably also need to include an
"&" to your command, otherwise your GUI will get stuck till the end of
the program.
Maybe you can find a different (more complicated) way of doing it using
fork(2) or some other function, but I never tried it.
Cheers,
m.
Manu C S wrote:
Hi,
I'm making a GUI for system commands.
For example, when a user clicks on a button, I want some system
command to be executed in the background and I want to trap the
output of the command and display it in my GUI.
For example, if I want to launch a browser from my gui
when a user clicks on a certain button, should I have this in
the callback function of that button:
system("mozilla");
Is that correct?
How do I handle commands that write to stdout?
I looked up the archives, but found nothing relevant.
Can anyone please help? It's rather urgent.
Thanks,
Manu
_______________________________________________
Glade-users maillist - Glade-users lists ximian com
http://lists.ximian.com/mailman/listinfo/glade-users
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]