-#define WXEXECUTE_NARGS 127
-
-long wxExecute( const wxString& command, int flags, wxProcess *process )
-{
- wxCHECK_MSG( !command.IsEmpty(), 0, wxT("can't exec empty command") );
-
- int argc = 0;
- wxChar *argv[WXEXECUTE_NARGS];
- wxString argument;
- const wxChar *cptr = command.c_str();
- wxChar quotechar = wxT('\0'); // is arg quoted?
- bool escaped = FALSE;
-
- // split the command line in arguments
- do
- {
- argument=wxT("");
- quotechar = wxT('\0');
-
- // eat leading whitespace:
- while ( wxIsspace(*cptr) )
- cptr++;
-
- if ( *cptr == wxT('\'') || *cptr == wxT('"') )
- quotechar = *cptr++;
-
- do
- {
- if ( *cptr == wxT('\\') && ! escaped )
- {
- escaped = TRUE;
- cptr++;
- continue;
- }
-
- // all other characters:
- argument += *cptr++;
- escaped = FALSE;
-
- // have we reached the end of the argument?
- if ( (*cptr == quotechar && ! escaped)
- || (quotechar == wxT('\0') && wxIsspace(*cptr))
- || *cptr == wxT('\0') )
- {
- wxASSERT_MSG( argc < WXEXECUTE_NARGS,
- wxT("too many arguments in wxExecute") );
-
- argv[argc] = new wxChar[argument.length() + 1];
- wxStrcpy(argv[argc], argument.c_str());
- argc++;
-
- // if not at end of buffer, swallow last character:
- if(*cptr)
- cptr++;
-
- break; // done with this one, start over
- }
- } while(*cptr);
- } while(*cptr);
- argv[argc] = NULL;
-
- // do execute the command
-#if wxUSE_UNICODE
- long lRc = -1;
-#else
- long lRc = wxExecute(argv, flags, process);
-#endif
-
- // clean up
- argc = 0;
- while( argv[argc] )
- delete [] argv[argc++];
-
- return lRc;
-}
-
-// ----------------------------------------------------------------------------
-// wxShell
-// ----------------------------------------------------------------------------
-
-static wxString wxMakeShellCommand(const wxString& command)
-{
- wxString cmd;
- if ( !command )
- {
- // just an interactive shell
- cmd = _T("xterm");
- }
- else
- {
- // execute command in a shell
- cmd << _T("/bin/sh -c '") << command << _T('\'');
- }
-
- return cmd;
-}
-
-bool wxShell(const wxString& command)
-{
- return wxExecute(wxMakeShellCommand(command), wxEXEC_SYNC) == 0;
-}
-
-bool wxShell(const wxString& command, wxArrayString& output)
-{
- wxCHECK_MSG( !!command, FALSE, _T("can't exec shell non interactively") );
-
- return wxExecute(wxMakeShellCommand(command), output);
-}
-