本文整理汇总了C++中spawnvp函数的典型用法代码示例。如果您正苦于以下问题:C++ spawnvp函数的具体用法?C++ spawnvp怎么用?C++ spawnvp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spawnvp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: RunCommand
static int RunCommand( const char *cmd )
{
char *cmdnam;
char *sp;
const char **argv;
int i;
cmdnam = strdup( cmd );
argv = malloc( strlen( cmd ) * sizeof( char * ) );
i = 0;
for( sp = cmdnam; sp != NULL; ) {
while( *sp != '\0' && *sp == ' ' )
++sp;
argv[i++] = sp;
sp = strchr( sp, ' ' );
if( sp != NULL ) {
*sp = '\0';
sp++;
}
}
argv[i] = NULL;
i = (int)spawnvp( P_WAIT, cmdnam, argv );
free( cmdnam );
free( (void *)argv );
return( i );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:26,代码来源:pmkcmd.c
示例2: w32system
int w32system(const char *cp)
{
char argbuf[256];
char *argv[32];
char *tp;
int argc;
tp = argbuf;
argc = 0;
while(*cp) {
while(*cp && (*cp == ' ')) cp++;
if(*cp) {
argv[argc++] = tp;
if(*cp == '"') {
cp++;
while(*cp && (*cp != '"')) *tp++ = *cp++;
if(*cp == '"') cp++;
}
else {
while(*cp && (*cp != ' ')) *tp++ = *cp++;
}
*tp++ = '\0';
}
}
argv[argc] = NULL;
return(spawnvp(P_WAIT, argv[0], argv));
}
开发者ID:MarcNo,项目名称:lifelines,代码行数:28,代码来源:w32systm.c
示例3: tclsh_main
int
tclsh_main(int ac, char **av)
{
char cmd[MAXPATH];
int ret;
pid_t pid;
sprintf(cmd, "%s/gui/bin/tclsh", bin);
unless(executable(cmd)) {
fprintf(stderr, "Cannot find the Tcl interpreter.\n");
exit(1);
}
av[0] = cmd;
spawn_tcl = 1;
if ((pid = spawnvp(_P_NOWAIT, av[0], av)) < 0) {
fprintf(stderr, "bk: cannot spawn %s\n", av[0]);
}
spawn_tcl = 0;
if (waitpid(pid, &ret, 0) < 0) {
return (126);
} else if (!WIFEXITED(ret)) {
return (127);
} else {
return (WEXITSTATUS(ret));
}
}
开发者ID:AlexShiLucky,项目名称:bitkeeper,代码行数:27,代码来源:tclsh.c
示例4: exec
static void exec( char *program, char *param ) {
static char *args[3];
int retcode;
assert( program != NULL );
assert( param != NULL );
#if DEBUG
printf("*** Search '%s'\n", program );
#endif
fn_split( program );
args[0] = xfind( fn_make(".exe"), getrundir() );
args[1] = param;
args[2] = NULL;
#if DEBUG
printf("*** Run '%s' '%s'\n", args[0], args[1] );
#endif
retcode = spawnvp( P_WAIT, args[0], (void *)args );
if ( retcode > 0 ) {
fprintf( stderr, "\n'%s' exitcode = %d\n", program, retcode );
if (! get_option(OPT_KEEPRSP) )
unlink( RESPONSE );
exit( retcode );
} else if ( retcode < 0 ) {
perror( program );
if (! get_option(OPT_KEEPRSP) )
unlink( RESPONSE );
exit(1);
}
}
开发者ID:doniexun,项目名称:OrangeC,代码行数:32,代码来源:GENER.c
示例5: ShellWrapper
ShellWrapper()
{
int iReturn;
iReturn = _pipe(iPipeIn_, 512, _O_TEXT | O_NOINHERIT);
assert(iReturn != -1);
iReturn = _pipe(iPipeOut_, 512, _O_TEXT | O_NOINHERIT);
assert(iReturn != -1);
//save old handle
int iStdin = _dup(_fileno(stdin));
int iStdout = _dup(_fileno(stdout));
int iStderr = _dup(_fileno(stderr));
iReturn = _dup2(iPipeOut_[0], _fileno(stdin));
assert(iReturn == 0);
iReturn = _dup2(iPipeIn_[1], _fileno(stdout));
assert(iReturn == 0);
iReturn = _dup2(iPipeIn_[1], _fileno(stderr));
assert(iReturn == 0);
char *arg[] = {"cmd.exe", "/Q", "/A", NULL};
iSubProcess_ = spawnvp(P_NOWAIT, arg[0], arg);
//restore old handle
iReturn = _dup2(iStdin, _fileno(stdin));
iReturn = _dup2(iStdout, _fileno(stdout));
iReturn = _dup2(iStderr, _fileno(stderr));
}
开发者ID:caicry,项目名称:my-windows-sdk,代码行数:28,代码来源:doc_3.cpp
示例6: os_startp
static int
os_startp (const char *shell, const char *command, const char *parm)
{
if (parm) {
char *argv[256],*par=strdup(parm),*p,i=0;
argv[i++]=strdup(shell);
argv[i++]=strdup("/c");
argv[i++]=strdup(command);
p=strtok(par," ");
while(p) {
argv[i++]=strdup(p);
p=strtok(0," ");
}
argv[i]=0;
spawnvp (P_WAIT,shell,argv);
i=0;
while(argv[i])free(argv[i++]);
free(par);
} else {
spawnlp (P_WAIT,
(char *) shell,
(char *) shell,
"/c",
(char *) command,
(char *) 0);
}
return 0;
}
开发者ID:OS2World,项目名称:UTIL-SHELL-Midnight_Commander,代码行数:28,代码来源:mysystem.c
示例7: msc_system
static int msc_system (const char *s)
{
char *par[10];
int i = 0;
char *p = (char *)b_cm__;
(void)strcpy(p,s);
while (*p==' ') p++; /* skip leading blanks */
while (*p!='\0')
{
par[i++] = p;
while (*p!=' ' && *p!='\0') p++; /* search next blank */
if (*p==' ')
{
*p = '\0'; /* store null char */
p++;
while (*p==' ') p++; /* skip leading blanks */
}
}
par [i] = NULL ;
return spawnvp (P_WAIT, par[0],par ) ;
}
开发者ID:skempken,项目名称:interverdikom,代码行数:25,代码来源:a_syst.c
示例8: execvp_win32
static int execvp_win32(const char *prog, char **argv)
{
int ret = spawnvp(P_NOWAIT, prog, (const char *const*)argv);
if (-1 == ret)
return ret;
cwait(&ret, ret, WAIT_CHILD);
exit(ret);
}
开发者ID:raldoni,项目名称:tcc,代码行数:8,代码来源:tcc.c
示例9: main
main(int argc, char *argv[])
{
clock_t clock(),starttime;
int status, i;
if (argc < 2)
{ printf("Time execution of a command.\nUse:\n\ttimer command\n");
exit(1);
}
argv[argc] = 0; /* terminate with a 0 (unportable method) */
starttime = clock();
/*
** This block added to keep arguments with embedded whitespace from getting
** broken up when timing is done. A *nix version should be a bit different.
** Also, the assignment to argv[i] technically isn't portable, but I don't
** know of an implementation where it causes a problem. <JC>
*/
for (i=1;i<argc;i++)
{
if (NULL != strchr(argv[i], ' '))
{
size_t len = strlen(argv[i]+3);
char *temp = malloc(len);
strcpy(temp+1, argv[i]);
temp[0] = '"';
temp[len-2] = '"';
temp[len-1] = '\0';
argv[i] = temp;
}
}
/* This reduces memory usage with MS compilers by releasing unused heap.
* Watcom may support it as well, but I'm not sure.
*/
#if defined(_QC) || defined(_MSC_VER)
_heapmin();
#endif
status = spawnvp(0,argv[1],SVP_CAST(argv + 1));
starttime = clock() - starttime;
if (status == -1)
{ printf("'%s' failed to execute\n",argv[1]);
exit(1);
}
#if !defined(__TURBOC__)
printf("Elapsed time = %d.%02d seconds\n",(int) (starttime/CLK_TCK),
(int) (starttime%CLK_TCK));
#else
printf("Elapsed time = %.2f seconds\n", starttime/CLK_TCK);
#endif
if (status != 0)
printf("--- errorlevel %d\n",status);
/* exit(0); changed to `return 0;' to reduce program size (minutely)
* and possibility or warnings that main doesn't return a value.
*/
return 0;
}
开发者ID:Eric-Schnipke,项目名称:snippets,代码行数:58,代码来源:timer.c
示例10: modsys_exec
static int modsys_exec( INSTANCE * my, int * params )
{
int mode = params[0];
char * filename = ( char * ) string_get( params[1] );
int argc = params[2];
char ** argv;
int n = 0;
#ifndef WIN32
pid_t child;
#endif
int status = -1;
// fill argv
argv = ( char ** ) calloc( argc + 2, sizeof( char * ) );
argv[0] = filename;
for ( n = 0; n < argc; n++ )
argv[n + 1] = ( char * ) string_get((( int * )( params[3] ) )[n] );
// Execute program
#ifdef WIN32
status = spawnvp( mode, filename, ( const char ** )argv );
#else
if (( child = fork() ) == -1 )
{
//Error
status = -1 ;
}
else if ( child == 0 )
{
execvp( filename, ( const char ** )argv );
exit(-1);
}
else
{
/* father */
switch ( mode )
{
case _P_WAIT:
if ( waitpid( child, &status, WUNTRACED ) != child )
status = -1;
else
status = (int)(char)WEXITSTATUS(status);
break;
case _P_NOWAIT:
status = child;
break;
}
}
#endif
// Free resources
string_discard( params[1] );
if ( argv ) free( argv );
return ( status ) ;
}
开发者ID:GarethNelson,项目名称:BennuGD,代码行数:57,代码来源:mod_sys.c
示例11: main
int main(int argc,char *argv[])
{
clock_t start,end;
FILE *fp;
int j;
char bb = 'f';
float var;
char aa[45]="The time that complies the program is : ";
cout << "Command line arguments:\n\n";
for (int i = 0; i < argc; ++i)
{
cout << "Argument [" << i << "] : " << argv[i] << '\n';
}
cout << "Measuring the time that needs to comply program ["
<< argv[i-1] << ".cpp" << ']' << "\n\n";
for(j=0;j<argc;++j)
{
if((argv[j][0]=='-') && (argv[j][1]=='o'))
{
fp=fopen(argv[j+1],"w");
bb = 't';
}
if((argv[j][0]=='b') && (argv[j][1]=='c') && (argv[j][2]=='c'))
argv=argv+j;
}
start = clock();
int result = spawnvp(P_WAIT,"bcc",argv);
end = clock();
var = (end - start) / CLK_TCK;
if (bb == 't')
{
fprintf(fp,"%s",aa);
fprintf(fp,"%8.3f %s",var,"second(s)");
fclose(fp);
}
if ((result != -1) && (bb != 't'))
{
cout << "The time that complies the program is : "
<< var << " second(s)" << '\n';
}
if (result == -1)
{
perror("execution error");
}
return result;
}
开发者ID:Abhay147,项目名称:BIN,代码行数:57,代码来源:TIMEIT.CPP
示例12: nmake
/*
* Spawn the Watcom wmake. Returns NMAKE_ERROR if wmake returned a bad
* status code or if it could not be spawned, or else NMAKE_SUCCESS if
* everything went smoothly.
*/
static int nmake( const OPT_STORAGE *cmdOpts, CmdLine *cmdLine )
/**************************************************************/
{
char ** args;
int rc;
int count;
char * cwd;
char flagstmp[32] = {0};
/*** get value for MAKEDIR field ***/
cwd = getcwd( NULL, 0 );
/*** construct MAKEFLAGS field ***/
if( cmdOpts->a ) strcat(flagstmp, "A");
if( cmdOpts->c ) strcat(flagstmp, "C");
if( cmdOpts->d ) strcat(flagstmp, "D");
if( cmdOpts->e ) strcat(flagstmp, "E");
if( cmdOpts->nologo ) strcat(flagstmp, "L");
if( cmdOpts->n ) strcat(flagstmp, "N");
if( cmdOpts->p ) strcat(flagstmp, "P");
if( cmdOpts->r ) strcat(flagstmp, "R");
if( cmdOpts->s ) strcat(flagstmp, "S");
if( cmdOpts->u ) strcat(flagstmp, "U");
if( cmdOpts->y ) strcat(flagstmp, "Y");
/*** pass builtin macros to wmake, so nmake wrapper gets called in recursive actions ***/
AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKE=\"%s\"", "nmake" );
AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKEDIR=\"%s\"", cwd );
AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKEFLAGS=\"%s\"", flagstmp );
/*** merge commands ***/
AppendCmdLine( cmdLine, NMAKE_PROGNAME_SECTION, MAKE );
args = MergeCmdLine( cmdLine, INVALID_MERGE_CMDLINE );
/*** Spawn the wmake ***/
if( cmdOpts->showwopts ) {
for( count=0; args[count]!=NULL; count++ ) {
fprintf( stderr, "%s ", args[count] );
}
fprintf( stderr, "\n" );
}
if( !cmdOpts->noinvoke ) {
rc = spawnvp( P_WAIT, MAKE, (const char **)args );
if( rc != 0 ) {
if( rc == -1 || rc == 255 ) {
FatalError( "Unable to execute '%s'", MAKE );
} else {
return( NMAKE_ERROR );
}
}
}
DestroyCmdLine( cmdLine );
return( NMAKE_SUCCESS );
}
开发者ID:Ukusbobra,项目名称:open-watcom-v2,代码行数:60,代码来源:nmake.c
示例13: Spawnvp
int Spawnvp(PCStr(what),PCStr(path),const char *const av[])
{ int pid;
if( DontFork ) {
return -1;
}
SpawnWhat = what;
MyPID = 0;
pid = spawnvp(SPAWN_P_NOWAIT,path,av);
return pid;
}
开发者ID:Nervous-,项目名称:Psiphon3-for-Linux,代码行数:11,代码来源:forkspawn.c
示例14: LineOutput
bool CDebuggerWin::CommandExecute(int argc, char **argv)
{
if(argc<2)
{
LineOutput("Invalid number of arguments");
return false;
}
else
{
spawnvp(_P_WAIT,argv[1],&argv[1]);
}
return true;
}
开发者ID:alexthissen,项目名称:handy-fork,代码行数:13,代码来源:Debuggerwin.cpp
示例15: start_screensaver
/* screen saver handler */
static BOOL start_screensaver( void )
{
if (using_root)
{
const char *argv[3] = { "xdg-screensaver", "activate", NULL };
int pid = spawnvp( _P_DETACH, argv[0], argv );
if (pid > 0)
{
WINE_TRACE( "started process %d\n", pid );
return TRUE;
}
}
return FALSE;
}
开发者ID:bpon,项目名称:wine,代码行数:15,代码来源:desktop.c
示例16: main
void main( int argc, char **argv )
{
int rc;
TIMESTAMP time;
if( argc <= 1 ) {
printf( "Usage: %s program [program args]\n", argv[0] );
exit( EXIT_SUCCESS );
}
init();
rc = spawnvp( P_WAIT, argv[1], (const char**)&argv[1] );
fini( &time );
printf( "%s: %dms, %dns\n", argv[1], time.millisecs, time.nanosecs );
exit( rc );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:15,代码来源:timer.c
示例17: run
/*---------------------------------------------------------------------*/
static int run(char *line, bool isvc)
{
char *nargv[10000];
char *ptr = line;
int i;
for ( i=0; i < 10000-1; i++ )
{
while ( *ptr == ' ' || *ptr == '\t' )
ptr++;
if ( *ptr == '\0' )
break;
if ( *ptr == '"' || *ptr == '\'' )
{
char lim = *ptr++;
nargv[i] = ptr;
while ( *ptr != lim && *ptr != '\0' )
{
if ( *ptr == '\\' && (*ptr == '"' || *ptr == '\'') )
memmove(ptr, ptr+1, strlen(ptr));
ptr++;
}
}
else
{
nargv[i] = ptr;
while ( *ptr != ' ' && *ptr != '\t' && *ptr != '\0' )
ptr++;
}
if ( *ptr != '\0' )
*ptr++ = '\0';
}
nargv[i] = NULL;
i = spawnvp(P_WAIT, nargv[0], nargv);
if ( i != 0 )
{
if ( i == -1 )
perror("exec error");
else
printf("ld error: '%s' exit with code %d\n", nargv[0], i);
exit(3);
}
else if ( isvc )
{
remove_exp_and_lib(nargv);
}
return 0;
}
开发者ID:nealey,项目名称:vera,代码行数:49,代码来源:ld.cpp
示例18: link
/*
* Link any object and library files. Returns LINK_NOACTION if there was no
* file to compile, LINK_ERROR if the linker returned a bad status code or
* if the compiler could not be spawned, or else LINK_SUCCESS if everything
* went smoothly.
*/
static int link( const OPT_STORAGE *cmdOpts, CmdLine *linkCmdLine )
/*****************************************************************/
{
char ** args;
char * filename;
int fileType;
int numFiles;
int rc;
char * defFile;
char * prevDefFile = NULL;
cmdOpts = cmdOpts;
/*** Process all object and library file names ***/
for( numFiles=0; ; numFiles++ ) {
filename = GetNextFile( &fileType, TYPE_OBJ_FILE, TYPE_LIB_FILE, TYPE_RES_FILE, TYPE_INVALID_FILE );
if( filename == NULL ) break;
AppendCmdLine( linkCmdLine, CL_L_FILENAMES_SECTION, filename );
}
/*** Process .def files ***/
for( ;; ) {
defFile = GetNextFile( NULL, TYPE_DEF_FILE, TYPE_INVALID_FILE );
if( defFile == NULL ) break;
if( prevDefFile != NULL ) {
Warning( "Overriding %s with %s", prevDefFile, defFile );
}
prevDefFile = defFile;
};
if( prevDefFile != NULL ) {
AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/DEF:%s", prevDefFile );
} else {
if( numFiles == 0 ) return( LINK_NOACTION );
}
/*** Spawn the linker ***/
AppendCmdLine( linkCmdLine, CL_L_PROGNAME_SECTION, LINKER );
args = MergeCmdLine( linkCmdLine, INVALID_MERGE_CMDLINE );
rc = spawnvp( P_WAIT, LINKER, (const char **)args );
if( rc != 0 ) {
if( rc == -1 || rc == 255 ) {
FatalError( "Unable to execute '%s'", LINKER );
} else {
return( LINK_ERROR );
}
}
return( LINK_SUCCESS );
}
开发者ID:Ukusbobra,项目名称:open-watcom-v2,代码行数:53,代码来源:cl.c
示例19: create_implib
/* run dlltool on .def file to create import library */
static void
create_implib (struct def_file *def, void *arg)
{
char *def_name;
char *lib_name;
char *p;
int r;
static char *argv[] = {NULL,
"--as", NULL,
"--output-lib", NULL,
"--def", NULL,
"--dllname", NULL,
"-k",
NULL};
fclose (def->f);
def_name = xmalloc (strlen (def->dllname) + 5);
lib_name = xmalloc (strlen (def->dllname) + 5);
dll_to_def_name (def_name, def->dllname);
p = strrchr (def->dllname, '.');
if (p)
{
*p = '\0';
sprintf (lib_name, "lib%s.a", def->dllname);
*p = '.';
}
else
sprintf (lib_name, "lib%s.a", def->dllname);
if (!keep_case)
for (p = lib_name + 3; *p; p++)
*p = tolower (*p);
argv[0] = dlltool_program;
argv[2] = as_program;
argv[4] = lib_name;
argv[6] = def_name;
argv[8] = def->dllname;
r = spawnvp (P_WAIT, argv[0], argv);
if (r == -1)
error (1, argv[0]);
free (lib_name);
free (def_name);
}
开发者ID:Mocahteam,项目名称:SpringPP,代码行数:46,代码来源:reimp.c
示例20: wxExecute
// wxExecute implementation
//
long wxExecute(wxChar **argv, int flags, wxProcess *process,
const wxString* cwd, const wxEnvVariableHashMap* env)
{
#if wxUSE_STREAMS
const int STDIN = 0;
const int STDOUT = 1;
const int STDERR = 2;
wxRedirectableFd in(STDIN), out(STDOUT), err(STDERR);
bool redirect = process && process->IsRedirected() && (flags & wxEXEC_SYNC);
if (redirect)
{
// close stdin/out/err and reopen them as files
if (!in.Reopen(wxT("NUL"), O_RDONLY | O_TEXT))
return -1;
if (!out.Reopen(wxFileName::CreateTempFileName(wxT("out")),
O_CREAT | O_WRONLY | O_TRUNC | O_TEXT))
return -1;
if (!err.Reopen(wxFileName::CreateTempFileName(wxT("err")),
O_CREAT | O_WRONLY | O_TRUNC | O_TEXT))
return -1;
}
#endif // wxUSE_STREAMS
// FIXME: suspend/resume gui
int mode = flags & wxEXEC_SYNC ? P_WAIT : P_NOWAIT;
int result = spawnvp(mode, argv[0], argv);
if (result == -1)
{
wxLogSysError(_("can't execute '%s'"), argv[0]);
}
#if wxUSE_STREAMS
if (redirect)
process->SetPipeStreams(new wxTempFileInStream(out.Release()),
new wxFFileOutputStream(wxT("NUL"), wxT("wt")),
new wxTempFileInStream(err.Release()));
#endif // wxUSE_STREAMS
return result;
}
开发者ID:yinglang,项目名称:newton-dynamics,代码行数:47,代码来源:utilsdos.cpp
注:本文中的spawnvp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论