# System command is wierd

**URL:** <https://www.ruby-forum.com/t/system-command-is-wierd/127768>\
**Category:** Ruby\
**Created:** [February 1, 2008, 4:50am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768 "2008-02-01T04:50:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [February 1, 2008, 4:50am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768/1 "2008-02-01T04:50:55Z")

</div>

Hello. this system command works from the command prompt but not from  
irb. when i have a space in the directory name, the irb system command  
cannot take it.

irb(main):008:0\> system(“dir e:\program files”)  
Volume in drive E has no label.  
Volume Serial Number is N857-EB60

Directory of e:\

File Not Found

Directory of E:\Documents and Settings\rocky

File Not Found  
=\> false

When i try this thro command prompt, it works  
E:\Documents and Settings\rocky\>dir “e:\program files”  
Volume in drive E has no label.  
Volume Serial Number is B857-EB62

Directory of e:\program files

26/01/2008 06:41 PM .  
26/01/2008 06:41 PM … …

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [February 1, 2008, 4:55am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768/2 "2008-02-01T04:55:36Z")

</div>

On Jan 31, 2008, at 19:49 , Junkone wrote:

> irb(main):008:0\> system(“dir e:\program files”)  
> E:\Documents and Settings\rocky\>dir “e:\program files”

compare what you’re doing in both and notice how they’re different.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [February 1, 2008, 4:56am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768/3 "2008-02-01T04:56:12Z")

</div>

Junkone wrote:

> File Not Found  
> Volume Serial Number is B857-EB62
> 
> Directory of e:\program files
> 
> 26/01/2008 06:41 PM .  
> 26/01/2008 06:41 PM … …

Have you tried system(‘dir e:\“program files”’) ?  
This works for me in irb.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [February 1, 2008, 9:19am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768/4 "2008-02-01T09:19:16Z")

</div>

Hi,

At Fri, 1 Feb 2008 13:06:56 +0900,  
Dan wrote in [ruby-talk:289420]:

> you could use
> 
> system(‘dir “e:/program files”’)

dir is an internal command, and you can’t use forward slashes  
as director separators.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [February 1, 2008, 5:07am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768/5 "2008-02-01T05:07:55Z")

</div>

If i recall correctly, ruby will convert paths between different os’s if  
it  
can.

So instead of

system(‘dir e:\“program files”’)

you could use

system(‘dir “e:/program files”’)

and save yourself escaping the backslash.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [February 2, 2008, 1:15am UTC](https://www.ruby-forum.com/t/system-command-is-wierd/127768/6 "2008-02-02T01:15:41Z")

</div>

Yeah

Windows/DOS has accepted either / or \ as directory separators for a  
while:

> **[Path (computing)](https://en.wikipedia.org/wiki/Path_(computing)#Representations_of_paths_by_operating_system)**
>
> A path is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/"), the backslash character ("\\"), or colon (":"), though some operating systems may use a different delimiter. Paths are used extensively in computer science to represent the directory/file relationships com...

However as you said dir is an internal command and forward slash breaks  
with  
it on the windows command line, but it does work in irb and stand-alone  
ruby.

irb(main):001:0\> system(‘dir “d:/program files”’)  
Volume in drive D is WINDOWS  
Volume Serial Number is 847A-A69A

Directory of d:\program files

13/01/2008 05:21 PM .  
13/01/2008 05:21 PM …  
13/01/2008 05:30 PM Cakewalk  
24/10/2007 12:04 AM Common Files  
24/10/2007 12:03 AM ComPlus Applications  
10/11/2007 11:11 PM DAEMON Tools  
03/01/2008 05:12 PM DIFX  
24/10/2007 12:48 AM Internet Explorer  
04/01/2008 09:28 AM Java  
24/10/2007 12:19 AM Messenger  
24/10/2007 12:36 AM MSBuild  
24/10/2007 12:40 AM MSXML 6.0  
24/10/2007 12:31 AM Reference Assemblies  
12/12/2007 09:03 PM TortoiseSVN  
02/11/2007 04:09 PM vim71  
24/10/2007 12:03 AM Windows NT  
0 File(s) 0 bytes  
18 Dir(s) 5,931,704,320 bytes free  
=\> true
