CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



macpharlan
New User

Oct 19, 2017, 11:07 AM

Post #1 of 4 (1254 views)
Why have my system commands stopped working(windows) Can't Post

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

Post #2 of 4 (1252 views)
Re: [macpharlan] Why have my system commands stopped working(windows) [In reply to] Can't Post

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

Post #3 of 4 (1251 views)
Re: [macpharlan] Why have my system commands stopped working(windows) [In reply to] Can't Post

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

Post #4 of 4 (1246 views)
Re: [macpharlan] Why have my system commands stopped working(windows) [In reply to] Can't Post

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 '*';


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives