]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/utilsexc.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Execution-related utilities
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation
25 #ifdef __HIDE_FORBIDDEN_NAMES
26 #undefine __HIDE_FORBIDDEN_NAMES
30 /*because 'noshare' is not valid in vax C++*/
38 #if defined(_AIX) || defined(__xlC__)
39 #include <sys/socket.h>
40 #include <sys/select.h>
43 #include <sys/syscall.h>
58 struct wxLocalProcessData
65 // somehow missing from sys/wait.h but in the system's docs
68 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
73 void xt_notify_end_process(XtPointer client
, int *fid
,
76 wxLocalProcessData
*process_data
= (wxLocalProcessData
*)client
;
80 pid
= (process_data
->pid
> 0) ? process_data
->pid
: -(process_data
->pid
);
82 /* wait4 is not part of any standard, use at own risk
83 * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-)
84 * --- offer@sgi.com */
86 wait4(process_data
->pid
, NULL
, 0, NULL
);
88 wait3((int *) NULL
, 0, (rusage
*) NULL
);
92 if (process_data
->process
)
93 process_data
->process
->OnTerminate(process_data
->pid
);
95 process_data
->end_process
= TRUE
;
97 if (process_data
->pid
> 0)
100 process_data
->pid
= 0;
103 long wxExecute(char **argv
, bool sync
, wxProcess
*handler
)
109 return 0; // Nothing???
115 /* fork the process */
116 #if defined(sun) || defined(__ultrix) || defined(__bsdi__)
117 pid_t pid
= vfork ();
128 /* GUILHEM: Close all fds when sync == 0 */
130 for (int fd
=0;fd
<FD_SETSIZE
;fd
++) {
131 if (proc_link
[1] != fd
)
136 execvp ((const char *)*argv
, (const char **)argv
);
138 execvp (*argv
, argv
);
140 /* GUILHEM: Reopen output stream */
141 // open("/dev/console", O_WRONLY);
144 printf ("%s: command not found\n", *argv
);
147 printf ("wxWindows: could not execute '%s'\n", *argv
);
151 wxLocalProcessData
*process_data
= new wxLocalProcessData
;
153 process_data
->end_process
= 0;
154 process_data
->process
= handler
;
155 process_data
->pid
= (sync
) ? pid
: -pid
;
158 XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(), proc_link
[0],
159 (XtPointer
*) XtInputReadMask
,
160 (XtInputCallbackProc
) xt_notify_end_process
,
161 (XtPointer
) process_data
);
164 while (!process_data
->end_process
)
165 XtAppProcessEvent((XtAppContext
) wxTheApp
->GetAppContext(), XtIMAll
);
167 if (WIFEXITED(process_data
->end_process
) != 0)
168 return WEXITSTATUS(process_data
->end_process
);
178 long wxExecute (const wxString
& command
, bool sync
, wxProcess
* handler
)
183 if (command
.IsNull() || command
== "")
184 return 0; // Nothing to do
186 // Run a program the recomended way under X (XView)
190 const char *IFS
= " \t\n";
192 // Build argument vector
193 strncpy (tmp
, (const char*) command
, sizeof (tmp
) / sizeof (char) - 1);
194 tmp
[sizeof (tmp
) / sizeof (char) - 1] = '\0';
195 argv
[argc
++] = strtok (tmp
, IFS
);
196 while ((argv
[argc
++] = strtok (NULL
, IFS
)) != NULL
)
199 return wxExecute(argv
, sync
, handler
);