Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

system("start $command") in Win32

by bhardage (Initiate)
on Feb 01, 2008 at 21:01 UTC ( [id://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 (Patriarch) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-03-28 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found