[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Backquote command execution path problem

Felipe Navas

1/5/2007 3:42:00 AM

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"

--
(.) CAMPANHA DA FITA ASCII ( http://ar...)
/ \ Contra formatos proprietarios

4 Answers

Carlos

1/5/2007 9:52:00 AM

0

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



Robert Klemme

1/5/2007 9:54:00 AM

0

On 05.01.2007 04:42, 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"
>

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

Felipe Navas

1/5/2007 9:18:00 PM

0

Thank you Carlos !

On 1/5/07, Robert Klemme <shortcutter@googlemail.com> wrote:
> On 05.01.2007 04:42, 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"
> >
>
> 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
>
>


--
(.) CAMPANHA DA FITA ASCII ( http://ar...)
/ \ Contra formatos proprietarios

Rodrigo Bermejo

1/6/2007 7:19:00 PM

0

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"

--
Posted via http://www.ruby-....