Unix file commands using PHP's system function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ktsirig
    New Member
    • Oct 2005
    • 11

    Unix file commands using PHP's system function

    Hi all!
    I am confused as to how an old-good UNIX command, like

    cat text.txt > new_tex.txt

    can be used in PHP.
    I tried
    system (" cat text.txt > new_text.txt");

    but it didn't work, the file new_text.txt was left blank.
    Am I doing something wrong with the > ???
    Must I use something else instead of 'system' ?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, ktsirig.

    Might be a permissions issue. Try this instead:
    [code=php]
    copy('text.txt' , 'newtext.txt');
    [/code]

    Does the same thing, but without all the overhead of making a system() call. Plus, if anything goes wrong (such as 'permission denied'), PHP will throw a warning and let you know.

    Comment

    Working...