]>
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
18 #include "wx/process.h"
27 #ifdef __HIDE_FORBIDDEN_NAMES
28 #undefine __HIDE_FORBIDDEN_NAMES
32 /*because 'noshare' is not valid in vax C++*/
40 #if defined(__AIX__) || defined(__xlC__)
41 #include <sys/socket.h>
42 #include <sys/select.h>
44 #ifndef __DATA_GENERAL__
45 #include <sys/syscall.h>
57 #include <sys/systeminfo.h>
61 // somehow missing from sys/wait.h but in the system's docs
64 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
74 struct wxLocalProcessData
81 // somehow missing from sys/wait.h but in the system's docs
84 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
89 void xt_notify_end_process(XtPointer client
, int *fid
,
92 wxLocalProcessData
*process_data
= (wxLocalProcessData
*)client
;
96 pid
= (process_data
->pid
> 0) ? process_data
->pid
: -(process_data
->pid
);
98 /* wait4 is not part of any standard, use at own risk
99 * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-)
100 * --- offer@sgi.com */
101 #if !defined(__sgi) && !defined(__SGI__) && !defined(__ALPHA__) && !defined(__SUNCC__)
102 wait4(process_data
->pid
, NULL
, 0, NULL
);
104 wait3((int *) NULL
, 0, (rusage
*) NULL
);
108 if (process_data
->process
)
109 process_data
->process
->OnTerminate(process_data
->pid
, 0); // What should 'status' be?
111 process_data
->end_process
= TRUE
;
113 if (process_data->pid > 0) // synchronous
116 process_data->pid = 0;
121 long wxExecute(char **argv
, bool sync
, wxProcess
*handler
)
127 return 0; // Nothing???
133 /* fork the process */
134 #if defined(sun) || defined(__ultrix) || defined(__bsdi__)
135 pid_t pid
= vfork ();
146 /* GUILHEM: Close all fds when sync == 0 */
148 for (int fd
=0;fd
<FD_SETSIZE
;fd
++) {
149 if (proc_link
[1] != fd
)
154 execvp ((const char *)*argv
, (const char **)argv
);
156 execvp (*argv
, argv
);
158 /* GUILHEM: Reopen output stream */
159 // open("/dev/console", O_WRONLY);
162 printf ("%s: command not found\n", *argv
);
165 printf ("wxWindows: could not execute '%s'\n", *argv
);
169 wxLocalProcessData
*process_data
= new wxLocalProcessData
;
171 process_data
->end_process
= 0;
172 process_data
->process
= handler
;
173 process_data
->pid
= (sync
) ? pid
: -pid
;
176 XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(), proc_link
[0],
177 (XtPointer
*) XtInputReadMask
,
178 (XtInputCallbackProc
) xt_notify_end_process
,
179 (XtPointer
) process_data
);
183 while (!process_data
->end_process
)
184 XtAppProcessEvent((XtAppContext
) wxTheApp
->GetAppContext(), XtIMAll
);
186 if (WIFEXITED(process_data
->end_process
) != 0)
188 return WEXITSTATUS(process_data
->end_process
);
197 long wxExecute (const wxString
& command
, bool sync
, wxProcess
* handler
)
202 if (command
.IsNull() || command
== "")
203 return 0; // Nothing to do
205 // Run a program the recomended way under X (XView)
209 const char *IFS
= " \t\n";
211 // Build argument vector
212 strncpy (tmp
, (const char*) command
, sizeof (tmp
) / sizeof (char) - 1);
213 tmp
[sizeof (tmp
) / sizeof (char) - 1] = '\0';
214 argv
[argc
++] = strtok (tmp
, IFS
);
215 while ((argv
[argc
++] = strtok (NULL
, IFS
)) != NULL
)
218 return wxExecute(argv
, sync
, handler
);