]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/utilsexc.cpp
a47a39413048fc411dbed87e7cbf2ef990d7f338
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>
55 #include <sys/systeminfo.h>
59 // somehow missing from sys/wait.h but in the system's docs
62 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
72 struct wxLocalProcessData
79 // somehow missing from sys/wait.h but in the system's docs
82 pid_t
wait4(pid_t pid
, int *statusp
, int options
, struct rusage
87 void xt_notify_end_process(XtPointer client
, int *fid
,
90 wxLocalProcessData
*process_data
= (wxLocalProcessData
*)client
;
94 pid
= (process_data
->pid
> 0) ? process_data
->pid
: -(process_data
->pid
);
96 /* wait4 is not part of any standard, use at own risk
97 * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-)
98 * --- offer@sgi.com */
99 #if !defined(__sgi) && !defined(__ALPHA__)
100 wait4(process_data
->pid
, NULL
, 0, NULL
);
102 wait3((int *) NULL
, 0, (rusage
*) NULL
);
106 if (process_data
->process
)
107 process_data
->process
->OnTerminate(process_data
->pid
);
109 process_data
->end_process
= TRUE
;
111 if (process_data
->pid
> 0)
114 process_data
->pid
= 0;
117 long wxExecute(char **argv
, bool sync
, wxProcess
*handler
)
123 return 0; // Nothing???
129 /* fork the process */
130 #if defined(sun) || defined(__ultrix) || defined(__bsdi__)
131 pid_t pid
= vfork ();
142 /* GUILHEM: Close all fds when sync == 0 */
144 for (int fd
=0;fd
<FD_SETSIZE
;fd
++) {
145 if (proc_link
[1] != fd
)
150 execvp ((const char *)*argv
, (const char **)argv
);
152 execvp (*argv
, argv
);
154 /* GUILHEM: Reopen output stream */
155 // open("/dev/console", O_WRONLY);
158 printf ("%s: command not found\n", *argv
);
161 printf ("wxWindows: could not execute '%s'\n", *argv
);
165 wxLocalProcessData
*process_data
= new wxLocalProcessData
;
167 process_data
->end_process
= 0;
168 process_data
->process
= handler
;
169 process_data
->pid
= (sync
) ? pid
: -pid
;
172 XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(), proc_link
[0],
173 (XtPointer
*) XtInputReadMask
,
174 (XtInputCallbackProc
) xt_notify_end_process
,
175 (XtPointer
) process_data
);
178 while (!process_data
->end_process
)
179 XtAppProcessEvent((XtAppContext
) wxTheApp
->GetAppContext(), XtIMAll
);
181 if (WIFEXITED(process_data
->end_process
) != 0)
182 return WEXITSTATUS(process_data
->end_process
);
192 long wxExecute (const wxString
& command
, bool sync
, wxProcess
* handler
)
197 if (command
.IsNull() || command
== "")
198 return 0; // Nothing to do
200 // Run a program the recomended way under X (XView)
204 const char *IFS
= " \t\n";
206 // Build argument vector
207 strncpy (tmp
, (const char*) command
, sizeof (tmp
) / sizeof (char) - 1);
208 tmp
[sizeof (tmp
) / sizeof (char) - 1] = '\0';
209 argv
[argc
++] = strtok (tmp
, IFS
);
210 while ((argv
[argc
++] = strtok (NULL
, IFS
)) != NULL
)
213 return wxExecute(argv
, sync
, handler
);