From: Park Heesob Date: 2006-04-30T00:27:50+09:00 Subject: Re: can a ruby script perform a chdir on win xp? Hi, >From: "Bill Guindon" >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >Subject: can a ruby script perform a chdir on win xp? >Date: Sat, 29 Apr 2006 23:47:22 +0900 > >I want to run a ruby script, and end up in a different directory. >Possible? > >All of the obvious approaches (%x, ``, system()) can change >directories, but only for their own process, once the script ends, >you're right were you started. > >For those who wonder 'why?'... I have a Rake task that sets up new >projects by building a project directory tree, and a couple of stub >files. When I run it, I want to end up inside one of the project >dirs. > >-- >Bill Guindon (aka aGorilla) >The best answer to most questions is "it depends". > There was the same question in ruby-talk and the answer(http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/68095) is make test.bat like this: @rem = '--Ruby-- @echo off if "%TEMP%" == "" ( echo TEMP not set goto exit 2>nul ) SET ARG=%1 if "%1" == "" ( SET ARG=nil ) set TMP_BAT_FILE=%TEMP%\TMPBAT_%RANDOM%.bat :exec ruby -x -S Test.bat %TMP_BAT_FILE% %1 %2 %3 goto endofruby @rem '; #!ruby # ruby code here # write out Windows shell commands to the ARGV[0] filename File.open(ARGV[0],"w") { |f| f.puts('cd \download') } __END__ :endofruby @echo off if exist %TMP_BAT_FILE% call %TMP_BAT_FILE% del %TMP_BAT_FILE% 2> nul set TMP_BAT_FILE= -- Regards, Park Heesob