process control functionsthe functions in this section are used to launch or terminate the other processes.
::wxexecute
::wxexecutelong wxexecute(const wxstring& command, int sync = wxexec_async, wxprocess *callback = null) wxperl note: in wxperl this function is called wx::executecommand long wxexecute(char **argv, int flags = wxexec_async, wxprocess *callback = null) wxperl note: in wxperl this function is called wx::executeargs long wxexecute(const wxstring& command, wxarraystring& output, int flags = 0) wxperl note: in wxperl this function is called wx::executestdout and it only takes the command argument, and returns a 2-element list ( status, output ), where output is an array reference. long wxexecute(const wxstring& command, wxarraystring& output, wxarraystring& errors, int flags = 0) wxperl note: in wxperl this function is called wx::executestdoutstderr and it only takes the command argument, and returns a 3-element list ( status, output, errors ), where output and errors are array references. executes another program in unix or windows. the first form takes a command string, such as "emacs file.txt". the second form takes an array of values: a command, any number of arguments, terminated by null. the semantics of the third and fourth versions is different from the first two and is described in more details below. if flags parameter contains wxexec_async flag (the default), flow of control immediately returns. if it contains wxexec_sync, the current application waits until the other program has terminated. in the case of synchronous execution, the return value is the exit code of the process (which terminates by the moment the function returns) and will be -1 if the process couldn't be started and typically 0 if the process terminated successfully. also, while waiting for the process to terminate, wxexecute will call wxyield. because of this, by default this function disables all application windows to avoid unexpected reentrancies which could result from the users interaction with the program while the child process is running. if you are sure that it is safe to not disable the program windows, you may pass wxexec_nodisable flag to prevent this automatic disabling from happening. for asynchronous execution, however, the return value is the process id and zero value indicates that the command could not be executed. as an added complication, the return value of -1 in this case indicates that we didn't launch a new process, but connected to the running one (this can only happen in case of using dde under windows for command execution). in particular, in this, and only this, case the calling code will not get the notification about process termination. if callback isn't null and if execution is asynchronous, wxprocess::onterminate will be called when the process finishes. specifying this parameter also allows you to redirect the standard input and/or output of the process being launched by calling redirect. if the child process io is redirected, under windows the process window is not shown by default (this avoids having to flush an unnecessary console for the processes which don't create any windows anyhow) but a wxexec_nohide flag can be used to prevent this from happening, i.e. with this flag the child process window will be shown normally. under unix the flag wxexec_make_group_leader may be used to ensure that the new process is a group leader (this will create a new session if needed). calling wxkill passing wxkill_children will kill this process as well as all of its children (except those which have started their own session). finally, you may use the third overloaded version of this function to execute a process (always synchronously, the contents of flags is or'd with wxexec_sync) and capture its output in the array output. the fourth version adds the possibility to additionally capture the messages from standard error output in the errors array. nb: currently wxexecute() can only be used from the main thread, calling this function from another thread will result in an assert failure in debug build and won't work. see also wxshell, wxprocess, exec sample. parameters command
argv
flags
callback
include files <wx/utils.h>
::wxexitvoid wxexit() exits application after calling wxapp::onexit. should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to terminate the application. see wxcloseevent and wxapp. include files <wx/app.h>
::wxkillint wxkill(long pid, int sig = wxsigterm, wxkillerror *rc = null, int flags = 0) equivalent to the unix kill function: send the given signal sig to the process with pid pid. the valid signal values are
enum wxsignal { wxsignone = 0, // verify if the process exists under unix wxsighup, wxsigint, wxsigquit, wxsigill, wxsigtrap, wxsigabrt, wxsigemt, wxsigfpe, wxsigkill, // forcefully kill, dangerous! wxsigbus, wxsigsegv, wxsigsys, wxsigpipe, wxsigalrm, wxsigterm // terminate the process gently };wxsignone, wxsigkill and wxsigterm have the same meaning under both unix and windows but all the other signals are equivalent to wxsigterm under windows. returns 0 on success, -1 on failure. if rc parameter is not null, it will be filled with an element of wxkillerror enum:
enum wxkillerror { wxkill_ok, // no error wxkill_bad_signal, // no such signal wxkill_access_denied, // permission denied wxkill_no_process, // no such process wxkill_error // another, unspecified error };the flags parameter can be wxkill_nochildren (the default), or wxkill_children, in which case the child processes of this process will be killed too. note that under unix, for wxkill_children to work you should have created the process by passing wxexec_make_group_leader to wxexecute. see also wxprocess::kill, wxprocess::exists, exec sample include files <wx/utils.h>
::wxgetprocessidunsigned long wxgetprocessid() returns the number uniquely identifying the current process in the system. if an error occurs, 0 is returned. include files <wx/utils.h>
::wxshellbool wxshell(const wxstring& command = null) executes a command in an interactive shell window. if no command is specified, then just the shell is spawned. see also wxexecute, exec sample. include files <wx/utils.h>
::wxshutdownbool wxshutdown(wxshutdownflagsflags) this function shuts down or reboots the computer depending on the value of the flags. please notice that doing this requires the corresponding access rights (superuser under unix, se_shutdown privilege under windows nt) and that this function is only implemented under unix and win32. parameters flags
returns true on success, false if an error occurred. include files <wx/utils.h>
|