Forum: Ruby change windows drive

97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-11-13 12:50
I need to get access to my D: drive through command line to do certain
actions... I tried to do many things but it seems like it says
permission denied when changing the drive using ruby:
`d:`

any clue how can i do this?
thanks
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-11-13 12:54
(Received via mailing list)
On Wed, Nov 13, 2013 at 12:50 PM, Mario Ruiz <lists@ruby-forum.com>
wrote:
> I need to get access to my D: drive through command line to do certain
> actions... I tried to do many things but it seems like it says
> permission denied when changing the drive using ruby:
> `d:`

What exactly did you do?  And does the user have permissions on the
folder in question?

Kind regards

robert
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-11-13 13:03
irb(main):001:0> Dir.pwd
=> "C:/Users/Joel"
irb(main):002:0> Dir.chdir 'E:/'
=> 0
irb(main):003:0> Dir.pwd
=> "E:/"
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-11-13 16:15
Yes the user has permissions.
I need run a process going first to the folder so what i need to do is
from Ruby:
D:
cd d:/myrootfolder/
/folder1/myprocess.exe

This is done actually in a ruby thread
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-11-13 18:25
(Received via mailing list)
On Wed, Nov 13, 2013 at 4:15 PM, Mario Ruiz <lists@ruby-forum.com>
wrote:
> Yes the user has permissions.
> I need run a process going first to the folder so what i need to do is
> from Ruby:
> D:
> cd d:/myrootfolder/
> /folder1/myprocess.exe
>
> This is done actually in a ruby thread

Certainly not - this isn't even valid Ruby code:

$ ruby -c <<CODE
> D:
> cd d:/myrootfolder/
> /folder1/myprocess.exe
> CODE
-:1: syntax error, unexpected ':', expecting $end

So what did you _really_ do?  And what error message did you get?

Cheers

robert
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-11-13 18:33
Of course not.. i was just explaining, what i do is like this more or
less:

`
D:
cd d:/myrootfolder/
/folder1/myprocess.exe
`

Error:
Permission denied, even when doing just `D:`
so it seems it is not possible in ruby to select the drive in command
line
Abdb670e1c130f96f947a94d03c02efa?d=identicon&s=25 Eric Christopherson (echristopherson)
on 2013-11-13 21:16
(Received via mailing list)
On Wed, Nov 13, 2013 at 11:33 AM, Mario Ruiz <lists@ruby-forum.com>
wrote:

> Permission denied, even when doing just `D:`
> so it seems it is not possible in ruby to select the drive in command
> line
>
> --
> Posted via http://www.ruby-forum.com/.
>

I'm not exactly sure what's going on here, but it sort of looks like
Ruby
is trying to *run* `D:` in some way. At first I thought maybe the
backtick
operator just assumed the first word was the name of an executable file,
but then I found out that you can do `cd /d D:` (`cd` is built in to
Windows's cmd.exe, not a separate file). Then I wondered if maybe
cmd.exe
didn't accept `D:` on its command line, but--sure enough--`cmd /k D:`
works
fine.

I also noticed the backtick operator only seems to read up to the first
newline. You have to use `&&` between the Windows commands. E.g.:

    `cd /d D: && cd d:/myrootfolder/ && /folder1/myprocess.exe`

But I'm unclear as to why you don't use Ruby's Dir class methods to
change
drives/directories.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-11-13 21:33
(Received via mailing list)
On Wed, Nov 13, 2013 at 9:15 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
>>
>> Error:
>> Permission denied, even when doing just `D:`
>> so it seems it is not possible in ruby to select the drive in command
>> line

> I'm not exactly sure what's going on here, but it sort of looks like Ruby is
> trying to *run* `D:` in some way. At first I thought maybe the backtick
> operator just assumed the first word was the name of an executable file, but

Yes, that's most likely what's happening.  Ruby needs a program to
execute but "cd" is just an internal command of "cmd".  It's probably
better to do something like

system("cmd", "/c", "cd /d d:/myrootfolder && d:/folder1/myprocess.exe")

maybe also this works

system("cd /d d:/myrootfolder && d:/folder1/myprocess.exe")

> then I found out that you can do `cd /d D:` (`cd` is built in to Windows's
> cmd.exe, not a separate file). Then I wondered if maybe cmd.exe didn't
> accept `D:` on its command line, but--sure enough--`cmd /k D:` works fine.
>
> I also noticed the backtick operator only seems to read up to the first
> newline. You have to use `&&` between the Windows commands. E.g.:
>
>     `cd /d D: && cd d:/myrootfolder/ && /folder1/myprocess.exe`

"cd /d" can change drive and directory so only one "cd" is needed (see
above).

> But I'm unclear as to why you don't use Ruby's Dir class methods to change
> drives/directories.

Same here.

Kind regards

robert
E343747f7d54222f079ebcf86abdf2bd?d=identicon&s=25 M.S. Strauss-Cassel (Guest)
on 2013-11-14 03:40
(Received via mailing list)
http://www.youtube.com/watch?v=xZI-6AQLIQQ&sns=em

Please forgive the brevity/spelling errors.
This message is being sent from my iPhone
To contact me by phone please
Call
Office.: 1-212-702-4027
Mobil 1-917-653-7887
Fax (Secure Fax, no cover letter needed) 1-917-265-4744

This email is private and confidential. Unauthorized use of private and
confidential information is prohibited.
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-11-14 11:12
Eric Christopherson wrote in post #1127226:
> On Wed, Nov 13, 2013 at 11:33 AM, Mario Ruiz <lists@ruby-forum.com>
> wrote:


Thanks Eric this worked!!!
I don't use the Dir class because it changes also then the Dir for the
execution of the current code that is in a Sinatra... so changes also
the references to libraries and everything... :)

Thanks again
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-11-14 12:15
(Received via mailing list)
On Thu, Nov 14, 2013 at 11:12 AM, Mario Ruiz <lists@ruby-forum.com>
wrote:
> Eric Christopherson wrote in post #1127226:
>> On Wed, Nov 13, 2013 at 11:33 AM, Mario Ruiz <lists@ruby-forum.com>
>> wrote:
>
> Thanks Eric this worked!!!
> I don't use the Dir class because it changes also then the Dir for the
> execution of the current code that is in a Sinatra... so changes also
> the references to libraries and everything... :)

Remedy for that would be to fork the process, chdir and then exec:

$ ruby -e 'p Dir.pwd; fork { Dir.chdir("/"); exec("bash", "-c",
"pwd")}; p Dir.pwd'
"/tmp"
"/tmp"
$ /

Instead of "bash" you would execute your program.  If you need to wait
for termination you can do

$ ruby -e 'p Dir.pwd; ch = fork { Dir.chdir("/"); exec("bash", "-c",
"pwd")}; p Dir.pwd; Process.wait ch'
"/tmp"
"/tmp"
/

Kind regards

robert
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2013-11-14 18:37
(Received via mailing list)
On Nov 14, 2013, at 4:12 AM, Mario Ruiz <lists@ruby-forum.com> wrote:

> Thanks again
>
> --
> Posted via http://www.ruby-forum.com/.

Im a bit unclear on the issues, but couldnt you do this:

Dir.chdir("d:/myrootfolder/") do |rootfolder|
  `/folder/myprocess.exe`
end


?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.