If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

Running a system command

I'm building a complex C++ project using MSVC. As a pre-build step it runs a small Perl script (called "fixup.pl") whose job is to configure certain files which then get used later in the chain. Suppose (from within fixup.pl) I wanted to run a system process (such as an exe program or a DOS batch file). Is it possible to do that from a Perl script?

Re: Running a system command

Bumping this question as a new problem has come to light....

The perl system command seems to work - AND - if the launched program outputs any text, I can see the text in my command prompt (assuming I originally ran my perl script from a command prompt) - BUT - if I attempt to re-direct that output to a file - e.g.

fixup.pl > output.txt

it seems to work in Windows 7 - but not in Windows 8 or XP. It doesn't work - even if I attempt to do the redirection from within my perl script - e.g.

Re: Running a system command

redirection in that way isn't part of the normal application parameters (in fact the application doesn't even know about the redirection per se).

I'm not sure why this would have worked in W7 and not in W8/XP, maybe you had some special execution processor installed that took care of this.

Typically speaking, if you want redirection, you either have to do it "the hard way", by creating the file objects handles, then making the execute process adopt those handles as standard input and standard output.
ALternatively, you can take an easy way out and simply run everyting through the command processor. So the command would then end up being something like:

%comspec% /C the_exe_name arg1 arg2 arg3 > output.txt

you may need to get the "%comspec%" variable from the environment yourself and substitute it directly.

It just seems to be impossible to find one set of code that'll work everywhere! Do you happen to know if it's possible to get system information using a Perl script? In particular, is there a way to get the value of WINVER?

Re: Running a system command

As the rest of the project seems to be in c++, why not rewrite the perl script in c++?

Yeah, I must admit I'm seriously contemplating that. If I rewrite it in C++ it'll most likely work first time. And even if it doesn't, at least I know I'll be able to fix it !

I don't understand why programmers keep struggling with all this scripting stuff. It almost never works reliably in my experience - and even if you can make it work on one machine it rarely works the same on somebody else's!

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.