I have two files int the directory ‘/tmp’: test.txt ,test.pl
the content of test.txt is :
abcdefg
the content of the test.pl is:
#!/usr/bin/perl -w chdir '/tmp'; $data = `more test.txt`; open (MYFILE,">","newtest.txt") || die ("can not open this file"); print MYFILE $data;
Then in java class I write :
Process ps1= Runtime.getRuntime().exec("perl /tmp/test.pl ");
Then the content of the newtest.txt generated from the perl is :
::::::::::: test.txt ::::::::::: abcdefg
Here is the problem ,There is a difference
::::::: test.txt :::::::
but when I run ‘perl test.pl’ in linux , there is no difference between two files.
anyone knows the reason ? Thanks !
Advertisement
Answer
more
is the guilty one here. It’s intended for looking at a file one page at a time and waits for hitting e.g. SPACE to show the next page. Try cat
instead of more
to see if that is the reason.
more
tries to be smart and autodetect whether it was called in an interactive situation but sometimes it fails. Depending on its settings it might behave as cat
then, but you cannot be sure…