Jan Dubois sent on Thu, 27 Oct 2005 15:42:35 -0700:
  
  > On Thu, 27 Oct 2005, Suresh Govindachar wrote:
  >> Hello,
  >>
  >>   When a .bat file with just the line: cd c:\some\where
  >>   is executed from the Windows cmd shell, then when the
  >>   .bat file terminates, the directory of the shell would
  >>   have changed to c:\some\where.
  >>
  >>   How do I get the same effect after running a perl
  >>   script?
  >>
  >>   (See http://www.xs4all.nl/~waterlan/ for a more complex
  >>   shell change directory program.)
  >
  > This can't be done directly, as an application cannot
  > modify the parent processes environment.  It works for
  > .bat files because they are being executed by the shell
  > and not run separately.
  > 
  > The closest you can get is having your Perl script write a
  > batch file and then call that after the script returns.
  > Something like:
  > 
  >     del c:\temp\change_env.bat 2>nul
  >     perl my_script.pl
  >     if exist c:\temp\change_env.bat call c:\temp\change_env.bat
  
  Thanks Jan -- you got me thinking and I have a nifty solution
  (at least for Windows XP's cmd):

  The perl file is essentially:
       # file the_directory_figure_outer.pl
         print 'c:\some\where';

  The batch file is essentially:
       rem file easy_cd.bat
           @for /F "usebackq" %%i IN (`perl the_directory_figure_outer.pl`) DO 
@cd %%i 

  (Preceding should be all in one line.)

  Then just run easy_cd.bat and it will change the cmd shell's
  directory to whatever was printed by the perl script!

  (I have tested this scheme and it works;  so if it doesn't work
  for you, there must be a typo somewhere.)

  --Suresh

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to