Forum: Ruby Backquote command execution path problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
542c2bd335b44f5ae8a2448cbafdc9e0?d=identicon&s=25 Felipe Navas (Guest)
on 2007-01-06 19:30
(Received via mailing list)
C:\projeto>irb
irb(main):001:0> `cd`
=> "C:\\projeto\n"

How i change the path that the command will be executed ?

What must happen:

C:\projeto>irb
irb(main):001:0> YOUR_MAGIC_COMMAND("C:\\projeto\\blablabla")
irb(main):002:0> `cd`
=> "C:\\projeto\\blablabla\n"
63529e6fbb35dde336d471b569b84d87?d=identicon&s=25 Rodrigo Bermejo (rbermejo)
on 2007-01-06 20:19
Felipe Navas wrote:
> C:\projeto>irb
> irb(main):001:0> `cd`
> => "C:\\projeto\n"
>
> How i change the path that the command will be executed ?
>
> What must happen:
>
> C:\projeto>irb
> irb(main):001:0> YOUR_MAGIC_COMMAND("C:\\projeto\\blablabla")
> irb(main):002:0> `cd`
> => "C:\\projeto\\blablabla\n"

YOUR_DIR="C:\\projeto\\blablabla\n"
`cd #{YOUR_DIR}`
=> "C:\\projeto\\blablabla\n"
YOUR_DIR="C:\\projeto"
`cd #{YOUR_DIR}`
> => "C:\\projeto\n"
C2cd72c24873556e278b44b5b3c7ef33?d=identicon&s=25 Carlos (Guest)
on 2007-01-19 16:30
(Received via mailing list)
Felipe Navas wrote:

> C:\projeto>irb
> irb(main):001:0> `cd`
> => "C:\\projeto\n"
>
> How i change the path that the command will be executed ?
>
> What must happen:
>
> C:\projeto>irb
> irb(main):001:0> YOUR_MAGIC_COMMAND("C:\\projeto\\blablabla")

Dir.chdir('C:\\projeto\\blablabla')

> irb(main):002:0> `cd`
> => "C:\\projeto\\blablabla\n"

Greetings.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-01-19 16:30
(Received via mailing list)
On 05.01.2007 04:42, Felipe Navas wrote:
> irb(main):002:0> `cd`
> => "C:\\projeto\\blablabla\n"
>

Do you want to change the path of the Ruby script?  Then no "cd" in any
subprocess will help - that only changes the sub process's path.  Also,
you might be confusing "cd" with "pwd" for printing the path.  You
probably want this:

irb(main):001:0> Dir.pwd
=> "/home/robert"
irb(main):002:0> Dir.chdir "/tmp"
=> 0
irb(main):003:0> Dir.pwd
=> "/tmp"
irb(main):004:0> `pwd`
=> "/tmp\n"

Kind regards

  robert
542c2bd335b44f5ae8a2448cbafdc9e0?d=identicon&s=25 Felipe Navas (Guest)
on 2007-09-25 22:44
(Received via mailing list)
Thank you Carlos !
This topic is locked and can not be replied to.