Backquote command execution path problem

F

Felipe Navas

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

Carlos

Felipe said:
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.
--
 
R

Robert Klemme

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"

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
 
F

Felipe Navas

Thank you Carlos !

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
 
R

Rodrigo Bermejo

Felipe said:
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}`
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top