Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

"Invalid argument" error with exec()

by Sprad (Hermit)
on Dec 12, 2003 at 18:22 UTC ( #314372=perlquestion: print w/replies, xml ) Need Help??

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

I'm probably doing something stupid here, but I can't seem to figure it out. I have this line in a script:
exec "" or die "exec failed: $!\n";
It returns the error: exec failed: Invalid argument

I've tried using single quotes, double quotes, putting the "" in a scalar and passing that instead, using parens or not, using other commands instead of (such as 'dir')... Nothing seems to work.

Please make me kick myself.

Pre-submission update: I was double-checking some things before hitting 'create', and I found that running the line with warnings on will give a little more information: Can't exec "cmd.exe": Invalid argument at ... So maybe it's not my fault?

A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re: "Invalid argument" error with exec()
by talexb (Chancellor) on Dec 12, 2003 at 19:56 UTC

    So in English what that means is that Perl tried to shell out (as your script requested) but failed. This might have been a problem when your Perl was built, tested and installed .. or if you got your Perl from ActiveState, maybe your cmd.exe is in a non-standard location .. or maybe it's not on the current PATH.

    --t. alex
    Life is short: get busy!
Re: "Invalid argument" error with exec()
by tcf22 (Priest) on Dec 12, 2003 at 18:39 UTC
    On "perl, v5.8.1 built for MSWin32-x86-multi-thread"
    this worked fine:
    exec("") or die "Error $!\n";

    Update: Same code also worked on "perl, v5.8.0 built for i386-linux-thread-multi"

    - Tom

Re: "Invalid argument" error with exec()
by PodMaster (Abbot) on Dec 12, 2003 at 20:56 UTC
    on my machine you cannot type on the commandline and expect it to run. try exec $^X, qw[ -x -S].

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2023-02-06 16:04 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (34 votes). Check out past polls.