Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

system("start $command") in Win32

by bhardage (Initiate)
on Feb 01, 2008 at 21:01 UTC ( #665651=perlquestion: print w/replies, xml ) Need Help??

bhardage has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to run a GUI testing program using Perl in Cygwin on my Windows XP.
One of the lines in my example code is as follows:

system("start calc.exe");

As I understand it, this is how you start an application and get the Perl script to continue running (I obviously need this functionality to be able to test the application) in a Win32 system, but it's generating an error. I get the 'cannot execute "start": No such file or directory' error.

Any ideas on what I'm doing wrong? If worse comes to worse I'll look for a new module that allows background processes, but I thought I'd be able to do it this way. Could someone correct me please?

Replies are listed 'Best First'.
Re: system("start $command") in Win32
by BrowserUk (Pope) on Feb 01, 2008 at 21:15 UTC

    That's what you get for using cygwin. It works just fine from AS (or any native) perl.

    The problem lies in the fact that the start command is a shell (cmd.exe) built in command, but when you use system under cygwin, it doesn't fallback to using cmd.exe if it cannot find an executable to run the command you supply.

    The answer may be to do system "cmd.exe /c start calc.exe";

    Other alternatives include using cygwin's fork.

    BTW: Under AS/native perl, you can run a command asynchronously using system 1, "calc.exe";

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: system("start $command") in Win32
by dirving (Friar) on Feb 01, 2008 at 21:13 UTC
    You can write:
    system(1, "calc.exe")

    Note that is will only work on Windows and is totally unportable to other operating systems -- on most other systems you want to do a fork followed by exec.

    -- David Irving
Re: system("start $command") in Win32
by bhardage (Initiate) on Feb 01, 2008 at 21:17 UTC
    I've tried that, but it gives the same error with "1" instead of "start".
      Yes, that works. Thanks very much.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://665651]
Approved by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-06-22 17:30 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (108 votes). Check out past polls.