Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Changing directory in cmd window

by roho (Chancellor)
on Sep 28, 2009 at 19:55 UTC ( #797989=note: print w/replies, xml ) Need Help??


in reply to Changing directory in cmd window

Thanks to all for your input. Meanwhile I have continued looking for a solution and have found one.
I invoke the Perl program from a batch file and use '&' to run another batch file generated by the Perl program.

cda.bat

@echo off cda.pl %* & \bat\aa.bat

cda.pl

#!/usr/bin/perl ###################################################################### # Name: cda.pl # Desc: CD to alternate directory (optionally to sub-directory). ###################################################################### use strict; use warnings; my $dir = "\\newdir"; if (@ARGV) { $dir .= "\\subdir" . rj(2,'0',shift); } my $ofile = "\\bat\\aa.bat"; open(OFILE, '>', $ofile) or die "Error opening $ofile: $!\n"; print OFILE "cd $dir\n"; print OFILE "cls\n"; print OFILE "dir /p /ogen\n"; close OFILE; exit; ################################################################### # This subroutine adds commas and right-justifies input number. ################################################################### sub rj { my $pad = shift; my $dlm = shift; local($_)=@_; 1 while s/(.*\d)(\d\d\d)/$1,$2/; $_ = ${dlm}x($pad-length($_)).$_; }

"Its not how hard you work, its how much you get done."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://797989]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2020-02-17 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (71 votes). Check out past polls.

    Notices?