the > in UNIX

They have: 53 posts

Joined: Oct 2005

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' ?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Are you wanting the results you indicate in your example? if so, all you are doing is copying the contents of text.txt to new_text.txt. If this is so you could just use the copy function in PHP. (see http://www.php.net/copy )

If there is some other need, check what directory it is using. Try system("pwd > thisdirectory.txt"); or system("ls -la > dirlist.txt"); to get a listing of the files into a file. Make sure the file you are trying to copy is listed in there.

This will help you check to make sure the file youa re trying to act upon (trying to CAT in your example) is really available to PHP in the directory which it executes.

-Greg

02bunced's picture

He has: 412 posts

Joined: May 2005

See if it's a problem with the > by just doing what Greg said above or just doing
system("echo 'Hello' > hello.txt");

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.