backticks and system() no longer work

Posted by on 2013-12-03 17:16

I'm using perl v5.12.4 on a Win7 system

Backticks have stopped working. EG:

$cmd=`dir`; now returns a null string.

$cmd=`file.htm`; used to start the default browser on the named file. It no longer does anything.

System("dir"); similarly no longer works.

The commands work fine if entered on the command line or a batch file without perl.

Can anyone suggest a possible reason for this?

Is there some particular file responsible for handling backticks and system() which I might try to replace?

ActiveState Staff
Fri, 2014-01-10 13:03

If you are running this Perl under the SYSTEM userID (which you will be, if this is a service or running through IIS), the PATH and cwd values will be different from what you have at the command line, and from what you may have written the script to expect.

By default, SYSTEM ID does not have a path for most system commands. That would explain your issue with "dir" and with not opening files with a .htm extension. You may find your script starts to work if you provide full pathnames for the commands, and full commands rather than relying on file associations.