Change windows drive

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

irb(main):001:0> Dir.pwd
=> “C:/Users/Joel”
irb(main):002:0> Dir.chdir ‘E:/’
=> 0
irb(main):003:0> Dir.pwd
=> “E:/”

On Wed, Nov 13, 2013 at 12:50 PM, Mario R. [email protected]
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

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

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

On Wed, Nov 13, 2013 at 4:15 PM, Mario R. [email protected]
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

On Wed, Nov 13, 2013 at 9:15 PM, Eric C.
[email protected] 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

On Wed, Nov 13, 2013 at 11:33 AM, Mario R. [email protected]
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.

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.

Eric C. wrote in post #1127226:

On Wed, Nov 13, 2013 at 11:33 AM, Mario R. [email protected]
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… :slight_smile:

Thanks again

On Nov 14, 2013, at 4:12 AM, Mario R. [email protected]ain.invalid 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

?

On Thu, Nov 14, 2013 at 11:12 AM, Mario R. [email protected]
wrote:

Eric C. wrote in post #1127226:

On Wed, Nov 13, 2013 at 11:33 AM, Mario R. [email protected]
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… :slight_smile:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs