Home: Perl Programming Help: Intermediate:
Why have my system commands stopped working(windows)



macpharlan
New User

Oct 19, 2017, 11:07 AM


Views: 6847
Why have my system commands stopped working(windows)

I have scripts that run the system() procedure for years, calling a system command with parameters, like thus:

system("dir /AD /B");

This used to work fine, but recently I noticed my scripts failing, it looks like the system command is not longer handling system command parameters the same.

I get this error on the above command:
dir: cannot access '/AD': No such file or directory
dir: cannot access '/B': No such file or directory

It's not taking in the options, its trying to run the command on them. I noticed the same issue with other windows commands like rmdir.

I have been running this code for years, but we have updated our windows servers with security patches that must have changed something.

Anyone else see this and know a solution for getting the system() routine to work correctly?

Thanks a bunch


macpharlan
New User

Oct 19, 2017, 12:29 PM


Views: 6845
Re: [macpharlan] Why have my system commands stopped working(windows)

I found a solution, I noticed that I don't need spaces to run this command, so I removed them and it works.
dir/AD/B . instead of dir /AD /B .

something must have changed in the OS that affected how this is run.


BillKSmith
Veteran

Oct 19, 2017, 1:41 PM


Views: 6844
Re: [macpharlan] Why have my system commands stopped working(windows)

Spaces are valid characters in windows file name. Look at the system directory .../Program Files/.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Oct 19, 2017, 4:46 PM


Views: 6839
Re: [macpharlan] Why have my system commands stopped working(windows)

I just ran a test on my Win 10 system and was able to duplicate the issue.

Clearly something has changed in the OS and I suspect that this only happens on Windows version 6.2 and above (i.e., Win 8 and Win 10), but I can't confirm that until I go back to work tomorrow.

This issue is an example why you should try to avoid system calls when possible, especially if you want to maintain portability.

The perl way to write your example dir command is:

Code
say $_ for grep -d, glob '*';