Forum: Ruby && should work in a system call?

Posted by Roger Pack (Guest)
on 2012-10-10 19:18
(Received via mailing list)
Hello.
It appears this run both commands, as expected (the first one fails):

system("ffmpeg -i || ls")

so should this run both commands, if the first succeeds?

 system("ls && ls")
ls: &&: No such file or directory
ls: ls: No such file or directory
=> false

It doesn't seem to...but I could be mis understanding...
-r
Posted by Roger Pack (Guest)
on 2012-10-10 19:20
(Received via mailing list)
>  system("ls && ls")
> ls: &&: No such file or directory
> ls: ls: No such file or directory
> => false

I see now that it works in Linux, but not windows.  I'm guessing this
is a bug, but feedback is welcome...
-r

 system("ls && ls")
benchmark.rb        dense_long_to_int.cpp     Makefile
sparse_long_to_double.cpp
benchmark.rb        dense_long_to_int.cpp     Makefile
sparse_long_to_double.cpp
 => true
Posted by Bartosz Dziewoński (matmarex)
on 2012-10-10 19:49
(Received via mailing list)
2012/10/10 Roger Pack <rogerdpack2@gmail.com>:
>>  system("ls && ls")
>> ls: &&: No such file or directory
>> ls: ls: No such file or directory
>> => false
>
> I see now that it works in Linux, but not windows.  I'm guessing this
> is a bug, but feedback is welcome...

There is not `ls` command on Windows (unless you install cygwin /
mingw yourself). You're looking for `dir`.

-- Matma Rex
Posted by Roger Pack (Guest)
on 2012-10-10 20:27
(Received via mailing list)
>>>  system("ls && ls")
>>> ls: &&: No such file or directory
>>> ls: ls: No such file or directory
>>> => false
>>
>> I see now that it works in Linux, but not windows.  I'm guessing this
>> is a bug, but feedback is welcome...
>
> There is not `ls` command on Windows (unless you install cygwin /
> mingw yourself). You're looking for `dir`.

In this case, I have one:

$ whichr ls
higher in the list is executed first
C:\installs\devkit451\devkit451\bin\ls.exe
C:\Program Files (x86)\Git\bin\ls.exe

But it seems you can substitute any executable name in there to get
the offending behavior...
-r
Posted by Bartosz Dziewoński (matmarex)
on 2012-10-10 20:53
(Received via mailing list)
Hm, interesting; I didn't run the code before, but I tried now and
confirm your observations.

-- Matma Rex
Posted by Roger Pack (rogerdpack)
on 2012-10-11 20:10
Posted by Graham Menhennitt (Guest)
on 2012-10-12 11:10
(Received via mailing list)
On 11/10/2012 05:26, Roger Pack wrote:
> $ whichr ls
> higher in the list is executed first
> C:\installs\devkit451\devkit451\bin\ls.exe
> C:\Program Files (x86)\Git\bin\ls.exe
>
> But it seems you can substitute any executable name in there to get
> the offending behavior...
> -r
>
This is purely an educated guess... it possibly matters whether you have
a SHELL environment variable set. If you do and it's set to bash or sh
or csh, I think that this will work correctly. If it's not set, you'll
get the Windows shell: cmd.exe - I don't think that it will grok &&.

Graham
Posted by Roger Pack (Guest)
on 2012-10-12 15:40
(Received via mailing list)
> This is purely an educated guess... it possibly matters whether you have a
> SHELL environment variable set. If you do and it's set to bash or sh or csh,
> I think that this will work correctly. If it's not set, you'll get the
> Windows shell: cmd.exe - I don't think that it will grok &&.

Yes, I was surprised to learn that, at least with windows OS's I've
tried, cmd.exe *does* understand &&.  I'll be honest it surprised me
:)
-r
Posted by Jon Forums (jonm)
on 2012-10-12 17:34
Roger Pack wrote in post #1079580:
>> This is purely an educated guess... it possibly matters whether you have a
>> SHELL environment variable set. If you do and it's set to bash or sh or csh,
>> I think that this will work correctly. If it's not set, you'll get the
>> Windows shell: cmd.exe - I don't think that it will grok &&.
>
> Yes, I was surprised to learn that, at least with windows OS's I've
> tried, cmd.exe *does* understand &&.  I'll be honest it surprised me

Indeed, cmd.exe sometimes surprises us in a good way

C:\mruby-git>cd build && cmake -G Ninja .. && ninja all test
-- Build type not set, defaulting to 'RelWithDebInfo'
-- The C compiler identification is GNU 4.7.2
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
...
Total: 481
   OK: 481
   KO: 0
Crash: 0
 Time: 0.004001 seconds
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.