Re: UNIX shell commands in Windows
by planetscape (Chancellor) on Jun 23, 2005 at 17:25 UTC
|
| [reply] |
|
The problem with external links is that they can die on the vine without the courtesy of a termination notice... :)
Perl Power Tools & Cmd line Tools are gone with no forwarding address, Berkley Utilities fails the firewall test with the keyword "games", it may load outside $work! Unix Tools for DOS points to a jhacker page...the nerve...
Good resources all in all. planetscape++
Update: Minor edit to above paragraph.
pmonk4ever
"No trees were harmed in the creation of this node. However, a rather large number of electrons were somewhat inconvenienced."
| [reply] |
Re: UNIX shell commands in Windows
by ikegami (Patriarch) on Jun 23, 2005 at 16:11 UTC
|
use File::Copy;
copy($file_var, $another_file)
or die("Could not copy file: $!\n");
| [reply] [d/l] |
|
perl -MFile::Copy -MFatal=copy -e "copy('srcfile','dstfile')"
| [reply] [d/l] |
Re: UNIX shell commands in Windows
by kirbyk (Friar) on Jun 23, 2005 at 15:59 UTC
|
If you control the machines it will be run on, look into Cygwin. It's a decent set of unix tools that run under Windows.
| [reply] |
|
If the OP just wants the command line tools such as cat then cygwin is probably overkill. Unix Utils on sourceforge is a collection of UNIX command line ported for Windows and will probably do the trick.
| [reply] |
Re: UNIX shell commands in Windows
by marto (Cardinal) on Jun 23, 2005 at 16:00 UTC
|
Hi,
The cheap and nasty way would be to try:
type $file_var > $another_file
This should work.
Hope this helps
Cheers
Martin | [reply] [d/l] |
Re: UNIX shell commands in Windows
by anonymized user 468275 (Curate) on Jun 23, 2005 at 16:24 UTC
|
One of the raisons d'etre of perl is precisely to create a programming environment where shell commands can as far as possible be avoided in favour of the rich portable facilities perl offers. Okay, so it's one line in the shell or DOS. However, you could do a search and replace e.g. with perl -e to convert `cat x > y` into Cat( x,y ) so as to use something portable like:-
sub Cat{
local $/=undef();
open my $fh, "<" . shift();
open my $gh, ">" . shift();
$_=<$fh>; print $gh $_;
close $fh, $gh;
}
-S
| [reply] [d/l] |
|
| [reply] |
|
How is it better than File::Copy? It slurps the entire file into memory, doesn't check for errors and doesn't handle non-text files.
| [reply] |
|
|
|
Re: UNIX shell commands in Windows
by tlm (Prior) on Jun 23, 2005 at 16:00 UTC
|
| [reply] |
Re: UNIX shell commands in Windows
by dorko (Prior) on Jun 23, 2005 at 16:13 UTC
|
Given that you were searching ActivePerl, it sounds like you might be porting that UNIX script to Perl to run on Win32. If that's the case, try this:
use File::Copy;
my $file1 = "test1.txt";
my $file2 = "test2.txt";
copy ( "$file1", "$file2" ) or die "Copy failed: $!";
Cheers,
Brent
| [reply] [d/l] |
Re: UNIX shell commands in Windows
by jZed (Prior) on Jun 23, 2005 at 16:02 UTC
|
You can either use the cygwin utils (they can be used under "DOS" as well as under cygwin bash) or you might try Perl Power Tools which has perl versions of "cat" and many other *nix commands. | [reply] |
Re: UNIX shell commands in Windows
by gellyfish (Monsignor) on Jun 23, 2005 at 16:03 UTC
|
Or alternatively see PPT
/J\
| [reply] |
Re: UNIX shell commands in Windows
by blazar (Canon) on Jun 23, 2005 at 16:01 UTC
|
That should work, even under DOS, except that DOS env variables would make that, uhm, IIRC:
cat %file_var% > %another_file%
I hope, but cannot guarantee, it works with redirections.
Well, apart that most probably you do not have cat. But then I suggest you look up and download UNXUTILS/UNXUPDATE or switch to cygwin, whichever you like most. Or, more simply,
perl -pe '' [FILE1] [>FILE2]
would do. But then why not copy instead? In any case not much perl really implied up to this point. The real question is why do you "need" this?!? - smell of XY problem here, IMHO. | [reply] [d/l] [select] |