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

A

AznCollegeGuy

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
 
J

Jonathan Turkanis

AznCollegeGuy said:
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
 
K

Karsten Baumgarten

AznCollegeGuy said:
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).
 
A

AznCollegeGuy

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
 
A

AznCollegeGuy

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
 
A

AznCollegeGuy

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
 
A

Alex

-------

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top