Skip to content

Instantly share code, notes, and snippets.

@chitchcock
Forked from anonymous/spawnlp_test.c
Created July 9, 2013 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chitchcock/5959901 to your computer and use it in GitHub Desktop.
Save chitchcock/5959901 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
int main(int argc, char *argv[]) {
if (argc >= 3) {
// call out to cp and use the arguments passed to this program.
// We are using P_WAIT so that spawnlp waits for CP to return
// The second argument specifies the executable to run
// The third-fifth argument will become argv[0] - argv[2] of the executable
// The sixth argument indicates that the list of arguments is done
//
// For more information see http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/lib_ref/s/spawnlp.html
int retValue = spawnlp(P_WAIT, "cp", "cp", argv[1], argv[2], NULL);
printf("Return value of calling `cp %s %s` is %d\n", argv[1], argv[2], retValue);
} else {
printf("Please specify two files to copy\n");
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment