]>
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
26 #ifdef __HIDE_FORBIDDEN_NAMES
27 #undefine __HIDE_FORBIDDEN_NAMES
31 /*because 'noshare' is not valid in vax C++*/
39 #if defined(__AIX__) || defined(__xlC__)
40 #include <sys/socket.h>
41 #include <sys/select.h>
43 #ifndef __DATA_GENERAL__
44 #include <sys/syscall.h>
56 #include <sys/systeminfo.h>
60 // somehow missing from sys/wait.h but in the system's docs
63 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
73 struct wxLocalProcessData
80 // somehow missing from sys/wait.h but in the system's docs
83 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
88 void xt_notify_end_process(XtPointer client
, int *fid
,
91 wxLocalProcessData
*process_data
= (wxLocalProcessData
*)client
;
95 pid
= (process_data
->pid
> 0) ? process_data
->pid
: -(process_data
->pid
);
97 /* wait4 is not part of any standard, use at own risk
98 * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-)
99 * --- offer@sgi.com */
100 #if !defined(__sgi) && !defined(__ALPHA__)
101 wait4(process_data
->pid
, NULL
, 0, NULL
);
103 wait3((int *) NULL
, 0, (rusage
*) NULL
);
107 if (process_data
->process
)
108 process_data
->process
->OnTerminate(process_data
->pid
);
110 process_data
->end_process
= TRUE
;
112 if (process_data
->pid
> 0)
115 process_data
->pid
= 0;
118 long wxExecute(char **argv
, bool sync
, wxProcess
*handler
)
124 return 0; // Nothing???
130 /* fork the process */
131 #if defined(sun) || defined(__ultrix) || defined(__bsdi__)
132 pid_t pid
= vfork ();
143 /* GUILHEM: Close all fds when sync == 0 */
145 for (int fd
=0;fd
<FD_SETSIZE
;fd
++) {
146 if (proc_link
[1] != fd
)
151 execvp ((const char *)*argv
, (const char **)argv
);
153 execvp (*argv
, argv
);
155 /* GUILHEM: Reopen output stream */
156 // open("/dev/console", O_WRONLY);
159 printf ("%s: command not found\n", *argv
);
162 printf ("wxWindows: could not execute '%s'\n", *argv
);
166 wxLocalProcessData
*process_data
= new wxLocalProcessData
;
168 process_data
->end_process
= 0;
169 process_data
->process
= handler
;
170 process_data
->pid
= (sync
) ? pid
: -pid
;
173 XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(), proc_link
[0],
174 (XtPointer
*) XtInputReadMask
,
175 (XtInputCallbackProc
) xt_notify_end_process
,
176 (XtPointer
) process_data
);
179 while (!process_data
->end_process
)
180 XtAppProcessEvent((XtAppContext
) wxTheApp
->GetAppContext(), XtIMAll
);
182 if (WIFEXITED(process_data
->end_process
) != 0)
183 return WEXITSTATUS(process_data
->end_process
);
193 long wxExecute (const wxString
& command
, bool sync
, wxProcess
* handler
)
198 if (command
.IsNull() || command
== "")
199 return 0; // Nothing to do
201 // Run a program the recomended way under X (XView)
205 const char *IFS
= " \t\n";
207 // Build argument vector
208 strncpy (tmp
, (const char*) command
, sizeof (tmp
) / sizeof (char) - 1);
209 tmp
[sizeof (tmp
) / sizeof (char) - 1] = '\0';
210 argv
[argc
++] = strtok (tmp
, IFS
);
211 while ((argv
[argc
++] = strtok (NULL
, IFS
)) != NULL
)
214 return wxExecute(argv
, sync
, handler
);