Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:15:18+00:00 2026-05-23T23:15:18+00:00

On Windows (with AcitveState perl 5.8…), when I use system to invoke another program

  • 0

On Windows (with AcitveState perl 5.8…), when I use system to invoke another program from my perl script like this:

my $command="tool.exe"; # or 'C:\fullpath\tool.exe'
my $param = '...';
my $err = system($command, $param);
die("tool not found!") if $err == -1; # never used!
my $errno = $err>>8;
print "Command executed with error code: $errno\n";

I never can properly determine whether tool.exe can be found by system, because if it isn’t found (isn’t on the path, or the full path specified doesn’t exist) system will apparently automatically pass the command off to cmd.exe, which then will fail with either path-not-found (exit code 3) or with command-not-found exit code 1!

As you can see, there are no shell metacharacters on the command I specify, so I’m a bit confused how the shell gets in there.

Also note that I have checked (with ProcessExplorer) that when the tool.exe is on the path, no cmd.exe will be involved, i.e. perl.exe will be the direct parent process of tool.exe.

Workaround: (??)

The following will at least get me an exit code of 255if the command doesn’t exist, although it appears to be a bit hacky, as it will print Can't spawn "cmd.exe": No such file or directory at ... to STDERR.

my $command="tool.exe"; # or 'C:\fullpath\tool.exe'
my @args = ($command, '...');
my $err = system {$command} @args;
# die("tool not found!") if $err == -1; # never used!
my $errno = $err>>8;
die("tool not found!") if $errno == 255;
print "Command executed with error code: $errno\n";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:15:18+00:00Added an answer on May 23, 2026 at 11:15 pm

    Why don’tyou use the perl file exist check?

    if( -e $file_path)  
    {  
      #invoke the command  
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl module that I would like to use from Java. Is
I have a Perl program that I've written that parses SQL-like statements and creates
I have a Perl script that works on Windows XP. It uses File::Copy's move
I'm converting a Unix Perl script to run on Windows. I'm having a problem
I am converting a linux script from http://www.perlmonks.org/index.pl?node_id=217166 specifically this: #!/usr/bin/perl -w use strict;
I'm using ActiveState Perl on Windows Server 2003. I want to create a directory
I am using ActiveState Perl 5.6 on a Windows 2003 Server, and am having
Windows Forms: For System.Drawing there is a way to get the font height. Font
Windows API ::FindWindow function fails when called from Service application. GetLastError() also returns 0
I need to set up sqllite for Perl on a Windows box. However -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.