# Backquote command execution path problem

**URL:** <https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266>\
**Category:** Ruby\
**Created:** [January 6, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266 "2007-01-06T19:30:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [January 6, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266/1 "2007-01-06T19:30:51Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [January 6, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266/2 "2007-01-06T20:19:14Z")

</div>

Felipe N. 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”

---

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266/3 "2007-01-19T16:30:16Z")

</div>

Felipe N. 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.

---

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266/4 "2007-01-19T16:30:59Z")

</div>

On 05.01.2007 04:42, Felipe N. 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

---

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [September 25, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/backquote-command-execution-path-problem/81266/5 "2007-09-25T22:44:36Z")

</div>

Thank you Carlos !
