By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
Jul 23 '05 #2

P: n/a
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
Jul 23 '05 #3

P: n/a
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

Jul 23 '05 #4

P: n/a
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/...rpreter_to_you

regards,
Alex
Jul 23 '05 #5

P: n/a
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

Jul 23 '05 #6

P: n/a
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

Jul 23 '05 #7

P: n/a
>
-------

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
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.