c++ system call invoke perl running visual c++ 6.0

Discussion in 'C++' started by AznCollegeGuy, Feb 17, 2005.

  1. Hello,

    Im trying to invoke a simple perl script with in my visual c++ gui
    program to with c++'s system call feature:

    when i call:

    system("dir");

    it works

    when i call:

    system("c:\perl\bin\perl.exe c:\temp\perl.pl");

    it does not work

    when i cut and paste

    c:\perl\bin\perl.exe c:\temp\perl.pl

    into the command line, it works.

    Does anyone know why?

    Thanks,

    AG
     
    AznCollegeGuy, Feb 17, 2005
    #1
    1. Advertising

  2. AznCollegeGuy wrote:
    > Hello,
    >
    > Im trying to invoke a simple perl script with in my visual c++ gui
    > program to with c++'s system call feature:
    >
    > when i call:
    >
    > system("dir");
    >
    > it works
    >
    > when i call:
    >
    > system("c:\perl\bin\perl.exe c:\temp\perl.pl");
    >
    > it does not work
    >
    > when i cut and paste
    >
    > c:\perl\bin\perl.exe c:\temp\perl.pl
    >
    > into the command line, it works.
    >
    > Does anyone know why?


    The standard doesn't constraint implementations much in this area. However, you
    might try using double backslashes in the string literal.

    Jonathan
     
    Jonathan Turkanis, Feb 17, 2005
    #2
    1. Advertising

  3. AznCollegeGuy wrote:
    > Hello,
    >
    > Im trying to invoke a simple perl script with in my visual c++ gui
    > program to with c++'s system call feature:
    >
    > when i call:
    >
    > system("dir");
    >
    > it works
    >
    > when i call:
    >
    > system("c:\perl\bin\perl.exe c:\temp\perl.pl");
    >
    > it does not work
    >
    > when i cut and paste
    >
    > c:\perl\bin\perl.exe c:\temp\perl.pl
    >
    > into the command line, it works.
    >
    > Does anyone know why?
    >
    > Thanks,
    >
    > AG
    >



    system("c:\\perl\\bin\\perl.exe c:\\temp\\perl.pl");

    Note the double backslashes. A single backslash marks a beginning escape
    sequence (like \n for new line).

    --
    Regards,

    Karsten
     
    Karsten Baumgarten, Feb 17, 2005
    #3
  4. Have anyone gotten it to work??

    Yeah that what my friend suggested before this post...no can do...

    I think it has to do with the the directory location or something.

    I've tried unix slashes etc:

    system("c:/perl/bin/perl.exe c:/temp/perl.pl");

    system("c:\\perl\\bin\\perl.exe c:\\temp\\perl.pl");

    I wonder if using visual c++ 6.0 makes any differences

    Another problem is keeping the command prompt window open, sincee it
    closes it too quickly to see the errror messages.

    To keep command prompt window open you can type something like this:

    run: cmd /k ipconfig

    /k keep the window open

    AG
     
    AznCollegeGuy, Feb 17, 2005
    #4
  5. AznCollegeGuy

    Alex Guest

    On Thu, 17 Feb 2005 11:33:30 -0800, AznCollegeGuy wrote:

    > Hello,
    >
    > Im trying to invoke a simple perl script with in my visual c++ gui
    > program to with c++'s system call feature:


    An elegant solution would be using the perlembed module. With it you
    wouldn't have to call an external interpreter, and you can grab the output
    directly.

    Have a look at
    http://www.perl.com/doc/manual/html/pod/perlembed.html#Adding_a_Perl_interpreter_to_you

    regards,
    Alex
     
    Alex, Feb 17, 2005
    #5
  6. Yeah that possible but... I was still curious about how make system
    calls to invoke commands, .bat files, and .pl files from my c program.
    That we'll not have to use any modules.

    Thanks,

    AG
     
    AznCollegeGuy, Feb 17, 2005
    #6
  7. Ok Got it!

    It has to do with directory path in which the files sit strangely so...

    ok

    my c++ .exe sits here:

    my .exe sits here:

    c:\myprograms\testprog\bin\testprog.exe

    my source c++ sits here:

    c:\myprograms\testprog\

    when i run :

    system("perl c:\\temp\\perl.pl");

    for some reason it does not see the .pl although its there ( i checked
    )

    but now if i move that .pl file to where my source file sits ( not
    where my .exe file sits )

    c:\myprograms\testprog\

    it works!

    -------

    Where the .cpp files sits, it runs perfectly.

    Is there any way to cd to the right directory to call the program?
    rather than having coppies of the .pl file?

    system("cd c:\temp\test.pl");
    system("perl c:\\temp\\perl.pl");

    but it wil not work if u use:

    c:\myprograms\testprog\bin\

    this is where the .exe file sits...

    Can anyone explain why??

    Thanks,

    AG
     
    AznCollegeGuy, Feb 18, 2005
    #7
  8. AznCollegeGuy

    Alex Guest

    >
    > -------
    >
    > Where the .cpp files sits, it runs perfectly.
    >
    > Is there any way to cd to the right directory to call the program?
    > rather than having coppies of the .pl file?
    >
    > system("cd c:\temp\test.pl");
    > system("perl c:\\temp\\perl.pl");


    You could of course pass your commands to the commandline interpreter:

    system("cmd /C \"cd c:\\temp\" && \"perl c:\\temp\\perl.pl\"");

    In this scenario, you should consider using the CreateProcess() function
    from the Windows API (since your call wouldn't produce portable code
    anyway). You can hand the working directory directly to the command. Also
    you can define the process it's own environment, and you are not limited
    in the possible length of the command-line parameters.

    regards,
    Alex
     
    Alex, Feb 20, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel
    Replies:
    0
    Views:
    596
    Samuel
    Jul 30, 2003
  2. plork123

    call.invoke

    plork123, May 11, 2005, in forum: Java
    Replies:
    2
    Views:
    696
    plork123
    May 11, 2005
  3. Thirumalai
    Replies:
    0
    Views:
    763
    Thirumalai
    May 22, 2006
  4. alex goretoy
    Replies:
    0
    Views:
    507
    alex goretoy
    Jan 15, 2009
  5. alex goretoy
    Replies:
    0
    Views:
    543
    alex goretoy
    Jan 15, 2009
Loading...

Share This Page