Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

UNIX shell commands in Windows

by magnus (Pilgrim)
on Jun 23, 2005 at 15:55 UTC ( [id://469431]=perlquestion: print w/replies, xml ) Need Help??

magnus has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I've written a script in UNIX which runs great, but now has to be ported to run under DOS. Because I was in a hurry, I took hordes of shortcuts, which are now coming back to haunt me.

My problem is simple, yet an afternoon with SuperSearch and ActivePerl docs has not yet yielded up an answer to my simple but frustrating issue.

The issue is finding out how to get `cat $file_var > $another_file`; to run under DOS.

Thanks in advance,
Magnus

Replies are listed 'Best First'.
Re: UNIX shell commands in Windows
by planetscape (Chancellor) on Jun 23, 2005 at 17:25 UTC
      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."

Re: UNIX shell commands in Windows
by ikegami (Patriarch) on Jun 23, 2005 at 16:11 UTC

    Perl comes with a module with function for copying files:

    use File::Copy; copy($file_var, $another_file) or die("Could not copy file: $!\n");
      or
      perl -MFile::Copy -MFatal=copy -e "copy('srcfile','dstfile')"
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.

    -- Kirby, WhitePages.com

      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.
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
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

      The best reply to the OP but I wouldn't slurp the file up all at once (who knows how big it would be).

      Duh! use File::Copy.

      -derby
        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.
Re: UNIX shell commands in Windows
by tlm (Prior) on Jun 23, 2005 at 16:00 UTC
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

    -- Yeah, I'm a Delt.
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.
Re: UNIX shell commands in Windows
by gellyfish (Monsignor) on Jun 23, 2005 at 16:03 UTC

    Or alternatively see PPT

    /J\

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://469431]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found