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


In reply to Re: Changing directory in cmd window by roho
in thread Changing directory in cmd window by roho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.