Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Question regarding dos commands in perl

Options
  • 27-07-2009 7:33pm
    #1
    Closed Accounts Posts: 227 ✭✭


    Hi all,

    I basically need to change some files which are set as read only to be not read only using perl. I've been trying to use the dos attrib command,

    ie http://www.easydos.com/attrib.html

    It works fine in DOS,

    I've tried using backticks and the system function but I can't seem to get them working. I'm sorry I don't have access to my code to show you guys but I'm using forward slashes in the filepath. Has anyone got experience with achieving this using perl? what about Win32:File package?

    Thanks for your time lads, I would really appreciate it.


Comments

  • Closed Accounts Posts: 7,794 ✭✭✭JC 2K3


    Can you use forward slashes in DOS? I'll assume it's an option you can change...

    Are you making sure to escape the forward slashes?

    i.e.
    `attrib +r C:\/myfile.txt`
    
    or
    `attrib +r C:\\myfile.txt`
    
    if using backslashes.


  • Closed Accounts Posts: 580 ✭✭✭karlr42


    It's probably a better idea to use the Win32 module rather than a system() call, this seems to have what you want. Scroll up and down a few pages, some interesting discussion.


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    External commands can often be replaced with internal perl functions.
    attrib can be replaced by chmod().
    I also recommend using forward slashes. It makes code easier to read and works.
    chmod 0777, 'c:/path/to/myfile.txt';
    


  • Closed Accounts Posts: 580 ✭✭✭karlr42


    daymobrew wrote: »
    External commands can often be replaced with internal perl functions.
    attrib can be replaced by chmod().
    I also recommend using forward slashes. It makes code easier to read and works.
    chmod 0777, 'c:/path/to/myfile.txt';
    
    That would work, but probably worth mentioning chmod doesn't work as expected on Windows systems:
    http://docs.activestate.com/activeperl/5.10/faq/Windows/ActivePerl-Winfaq5.html#How_does_the_chmod_function_work
    Unrelated: I love chmod on *nix systems, such a simple and intuitive tool.


Advertisement