FAQ : running program inside program (spawn)

This is a discussion on FAQ : running program inside program (spawn) within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to use "spawn" function and/or "system()". I was successfull in running "system()" but I always had ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    23

    FAQ : running program inside program (spawn)

    Hi,
    I am trying to use "spawn" function and/or "system()". I was successfull in running "system()" but I always had to put the child program at a specific location (I do not know how to change path to point to the location of child program). So I then switched to using "spawn()".
    I am usig pretty simple arguments and settings and yet I get the error "Invalid Argument " (when I use perror). Please have a look at code below and if someone can tell me why?. I have tried several permuations and referred documentation in VC++ help as well but I can't seem to figure out right now
    Note: child program = "test_system.exe"
    Code:
    Code:
    char mode[]="_P_WAIT";
    	char path[]="C:\test_system.exe";
    	char path1[]="sdfor.exe";
    	char args[]="NULL";
    	//char path[]="test_system\test_system.exe";
    	printf("STart exe file\n");
    	i=spawnlp(mode,path,"test_system.exe",NULL);
    	perror("The message for error\n");
    	printf("%d",i);
    	printf("End of exe file\n");
    I hope I have used code tags the right way if not please let me know and I will repost


    Thanks
    Nipun
    Last edited by nipun; 06-13-2004 at 01:18 AM. Reason: Code Tags

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    Go read the manual page for spawnlp again, and pay attention to all warning messages.

    The first parameter should be just _P_WAIT
    Not a pointer to a string containing "_P_WAIT"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    23
    Thanks for the reply Salem,
    However that was not the only problem. I admit I didn't pay attention to mode and assumed it to be asking pointer to string. But more important is this observation which might help others who are new to using "spawn"
    My path file contained(if one sees in the code i posted above) C:\dir1\file.exe in my case it is
    C:\test_system\test_system.exe

    so it take "\t " as a tab and not as '\t' I rectified it by putting
    C:\\test_system\\test_system.exe and ofcourse _P_WAIT instead of "_P_WAIT"

    Hope this helps some other people as well
    Nipun

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    > so it take "\t " as a tab and not as '\t' I rectified it by putting
    Well yes, that's just normal 'C' quoting mechanism for escape characters in any string, nothing peculiar to strings being passed to spawn
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 02:17 PM
  2. Stop program from running twice?
    By Abda92 in forum C Programming
    Replies: 19
    Last Post: 03-17-2008, 02:35 PM
  3. Running program in unix
    By Cpro in forum Linux Programming
    Replies: 2
    Last Post: 02-10-2008, 09:28 PM
  4. Running my program.....estimated to take 55 hrs...
    By AssistMe in forum C Programming
    Replies: 14
    Last Post: 03-21-2005, 12:46 AM
  5. running another program
    By Skeptic in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2002, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21