Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using spawnlp in a QNX program to call out to cp in order to copy a file.
#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;
}
@chitchcock

This comment has been minimized.

Copy link

@chitchcock chitchcock commented Jul 9, 2013

Somehow I created this as an anonymous gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment