Thread: spawnl and char *

  1. #1
    Registered User lsegundo's Avatar
    Join Date
    Feb 2002
    Posts
    6

    Question spawnl and char *

    i know how to use spawnl (spawnl(P_WAIT,"myprog.exe","myprog.exe", agr0,...,NULL). the problem is that i am searching for a .exe and puting the path name in a string. spawnl wont execute a char *. this is what i mean:

    this works:
    spawnl(P_WAIT, "path\\myprog.exe", "path\\myprog.exe", NULL);

    this doesn't:
    char *pTr="path\\myprog.exe";
    spawnl(P_WAIT, pTr, PTr, NULL);

    i am running Vc++ on win98

    any suggestions???
    Last edited by lsegundo; 02-26-2002 at 12:23 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > spawnl wont execute a char *.
    C'mon - details please

    Error messages, status results, effects (or lack of)

  3. #3
    Registered User lsegundo's Avatar
    Join Date
    Feb 2002
    Posts
    6
    there is no error message from either the compiler or linker. no warning message either. it is as if this line of code simply wasnt there.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > there is no error message from either the compiler or linker. no warning message either
    And what about the int status result from spawn at run-time?

    Is this also correct?

  5. #5
    Registered User lsegundo's Avatar
    Join Date
    Feb 2002
    Posts
    6
    do you mean what spwanl returns after execution?? if so i haven't checked it. i was just wondering why it wont take a variable char *(as in char *pTr) as an argument.

  6. #6
    Registered User lsegundo's Avatar
    Join Date
    Feb 2002
    Posts
    6
    i figured out that spawnl, when using variable for the path, cant seem to locate the child. should i maybe be using a different member of the spawn family??

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Are you entirely sure that you haven't missed a \ for example?

    This works just fine here, using DJGPP
    Code:
    #include <stdio.h> 
    #include <process.h>
    
    void p1 ( void ) {
        int res = spawnl( P_WAIT,
            "c:\\winnt\\system32\\ping.exe",
            "c:\\winnt\\system32\\ping.exe",
            "127.0.0.1", NULL );
        printf( "Res=%d\n", res );
    }
    void p2 ( void ) {
        char *cmd = "c:\\winnt\\system32\\ping.exe";
        char *par = "127.0.0.1";
        int res = spawnl( P_WAIT, cmd, cmd, par, NULL );
        printf( "Res=%d\n", res );
    }
    
    int main ( ) {
        p1();
        p2();
        return 0;
    }

  8. #8
    Registered User lsegundo's Avatar
    Join Date
    Feb 2002
    Posts
    6
    this is what i am trying to do in a nut shell:

    FILE *fp;
    char *path;

    system("dir c:\\/s/b | grep -ir \\myprog.exe > fp.dat")\\this

    \\searches for myprog.exe and puts the path into fp.dat

    (nonimportant code that fixes the path to c:\\etc)

    path=(char *)malloc(MAXPATH*sizeof(char));
    fp=fopen("path.dat","r");
    fgets(path,MAXPATH,fp);
    spawnl(P_WAIT,path,path,NULL);

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > fgets(path,MAXPATH,fp);
    You need to remove the \n from the end of the line, before passing it to spawnl

    Otherwise, you're trying to run "prog.exe\n", not "prog.exe"

  10. #10
    Registered User lsegundo's Avatar
    Join Date
    Feb 2002
    Posts
    6
    THANK YOU!!! that damn problem has been killing me.
    THANX

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using spawnl for a dos program
    By ronin in forum C Programming
    Replies: 6
    Last Post: 06-30-2002, 09:34 PM