Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
system() on windows
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
snacktime  
View profile  
 More options Nov 24 2005, 4:21 pm
Newsgroups: comp.lang.ruby
From: snacktime <snackt...@gmail.com>
Date: Fri, 25 Nov 2005 06:21:03 +0900
Local: Thurs, Nov 24 2005 4:21 pm
Subject: system() on windows
I'm trying to figure out why a particular system command is returning
false on windows.

This works fine and returns true:

res = system('dir')

This returns false with $? being nil:

res = system('rake')

if I just run rake at the command line it works fine.   I'm sure this
is something simple, but windows is not a development environment I am
used to.

Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lyndon Samson  
View profile  
 More options Nov 24 2005, 5:03 pm
Newsgroups: comp.lang.ruby
From: Lyndon Samson <lyndon.sam...@gmail.com>
Date: Fri, 25 Nov 2005 07:03:38 +0900
Local: Thurs, Nov 24 2005 5:03 pm
Subject: Re: system() on windows

On 11/25/05, snacktime <snackt...@gmail.com> wrote:

> I'm trying to figure out why a particular system command is returning
> false on windows.

> This works fine and returns true:

> res = system('dir')

> This returns false with $? being nil:

> res = system('rake')

Windows return codes where never as standardised as Unix. Plus dir is part
of the command shell, not a standalone exec.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Damphyr  
View profile  
 More options Nov 24 2005, 7:43 pm
Newsgroups: comp.lang.ruby
From: Damphyr <damp...@freemail.gr>
Date: Fri, 25 Nov 2005 09:43:52 +0900
Local: Thurs, Nov 24 2005 7:43 pm
Subject: Re: system() on windows
snacktime wrote:
> I'm trying to figure out why a particular system command is returning
> false on windows.

> This works fine and returns true:

> res = system('dir')

> This returns false with $? being nil:

> res = system('rake')

> if I just run rake at the command line it works fine.   I'm sure this
> is something simple, but windows is not a development environment I am
> used to.

Try cmd=ExecCmd.new("rake");puts cmd.success?;puts cmd.output  using the
class at the end of this message (Ara's solution for grabbing the output
  of stderr and stdout on windows with a broken popen3 was better -
giving you separate stderr und stdout - but this one has benchmarking
too :) ).

I get

false
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
d:/dev/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1373:in
`load_rakefile'

on a directory without a rakefile, which is correct :).

system("rake") for the same directory gives a $? of 256.

--------
class ExecCmd
        attr_reader :output,:cmd,:exec_time
        #When a block is given, the command runs before yielding
        def initialize cmd
        @cmd=cmd
        @cmd_run=cmd+" 2>&1" unless cmd=~/2>&1/
        if block_given?
                run
                yield self
        end
        end
        #Runs the command
        def run
                t1=Time.now
                IO.popen(@cmd_run){|f|
                @output=f.read
                @process=Process.waitpid2(f.pid)[1]
                }
                @exec_time=Time.now-t1
        end
        #Returns false if the command hasn't been executed yet
        def run?
                return false unless @process
                return true
        end
        #Returns the exit code for the command. Runs the command if it hasn't
run yet.
        def exitcode
                run unless @process
                @process.exitstatus
        end
        #Returns true if the command was succesfull.
        #
        #Will return false if the command hasn't been executed
        def success?
                return @process.success? if @process
                return false
        end
end

--
http://www.braveworld.net/riva

____________________________________________________________________
http://www.freemail.gr - δωρεάν υπηρεσία ηλεκτρονικού ταχυδρομείου.
http://www.freemail.gr - free email service for the Greek-speaking.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
snacktime  
View profile  
 More options Nov 25 2005, 2:18 am
Newsgroups: comp.lang.ruby
From: snacktime <snackt...@gmail.com>
Date: Fri, 25 Nov 2005 16:18:53 +0900
Local: Fri, Nov 25 2005 2:18 am
Subject: Re: system() on windows
On 11/24/05, Damphyr <damp...@freemail.gr> wrote:

> Try cmd=ExecCmd.new("rake");puts cmd.success?;puts cmd.output  using the
> class at the end of this message (Ara's solution for grabbing the output
>   of stderr and stdout on windows with a broken popen3 was better -
> giving you separate stderr und stdout - but this one has benchmarking
> too :) ).

In initialize block_given? is returning false for me.  Any idea why?

Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaspar Schiess  
View profile  
 More options Nov 25 2005, 3:04 am
Newsgroups: comp.lang.ruby
From: Kaspar Schiess <e...@space.ch>
Date: Fri, 25 Nov 2005 17:04:27 +0900
Local: Fri, Nov 25 2005 3:04 am
Subject: Re: system() on windows
(In response to
news:1f060c4c0511241320g4bf0af9bs16f14b86e51d358f@mail.gmail.com by
snacktime)

> res = system('rake')

I call ruby scripts by
  system('cmd.exe /c rake')

Sadly, system seems to be broken many ways on windows.

kaspar
--
code manufacture & ruby lab at http://www.tua.ch/ruby


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Damphyr  
View profile  
 More options Nov 25 2005, 3:23 am
Newsgroups: comp.lang.ruby
From: Damphyr <damp...@freemail.gr>
Date: Fri, 25 Nov 2005 17:23:53 +0900
Local: Fri, Nov 25 2005 3:23 am
Subject: Re: system() on windows
snacktime wrote:
> On 11/24/05, Damphyr <damp...@freemail.gr> wrote:

>>Try cmd=ExecCmd.new("rake");puts cmd.success?;puts cmd.output  using the
>>class at the end of this message (Ara's solution for grabbing the output
>>  of stderr and stdout on windows with a broken popen3 was better -
>>giving you separate stderr und stdout - but this one has benchmarking
>>too :) ).

> In initialize block_given? is returning false for me.  Any idea why?

Did you pass a block? Actually I missed cmd.run in there (what do you
expect at quarter to two?).

You can do it like this:

ExecCmd.new("rake"){|cmd|
        puts cmd.success?
        puts cmd.output

}

or like this:

cmd=ExecCmd.new("rake")
cmd.run
puts cmd.success?
puts cmd.output

But a nice sideeffect of this implementation was
cmd1=ExecCmd.new("blabla")
cmd2=ExecCmd.new("blabla2")
cmd3=ExecCmd.new("blabla3")
[cmd1,cmd2,cmd3].each{|cmd|
        cmd.run
        #do stuff with it

}

And afterwards you also have a crude benchmark for each command i.e. :)
[cmd1,cmd2,cmd3]each{|cmd|
        if cmd.run?
                status="succeeded"
                status="failed" unless cmd.success?
                puts "#{cmd.cmd} #{status} in #{cmd.exec_time}s"
                puts "Log:\n#{cmd.output}" unless cmd.success?
        else
                puts "#{cmd.cmd} was not executed"
        end
}

--
http://www.braveworld.net/riva

____________________________________________________________________
http://www.freemail.gr - δωρεάν υπηρεσία ηλεκτρονικού ταχυδρομείου.
http://www.freemail.gr - free email service for the Greek-speaking.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gregarican  
View profile  
 More options Nov 25 2005, 11:06 am
Newsgroups: comp.lang.ruby
From: "gregarican" <greg.kuj...@gmail.com>
Date: 25 Nov 2005 08:06:52 -0800
Local: Fri, Nov 25 2005 11:06 am
Subject: Re: system() on windows

Kaspar Schiess wrote:
> I call ruby scripts by
>   system('cmd.exe /c rake')

> Sadly, system seems to be broken many ways on windows.

> kaspar

How is this broken? the system() method works directly with the Windows
shell. And the rake command isn't contained within the Windows shell as
an internal command. That's why system('dir') works and system('rake')
doesn't. This would seem logical in my opinion and I am far from a
Microsoft fanboy :-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaspar Schiess  
View profile  
 More options Nov 25 2005, 12:50 pm
Newsgroups: comp.lang.ruby
From: Kaspar Schiess <e...@space.ch>
Date: Sat, 26 Nov 2005 02:50:43 +0900
Local: Fri, Nov 25 2005 12:50 pm
Subject: Re: system() on windows
Hi gregarican,

> How is this broken? the system() method works directly with the Windows
> shell. And the rake command isn't contained within the Windows shell as
> an internal command. That's why system('dir') works and system('rake')
> doesn't. This would seem logical in my opinion and I am far from a
> Microsoft fanboy :-)

On my unix shell:
--------------------------
eule@makkara:~> rake
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake.rb:1222:in
`load_rakefile'
eule@makkara:~> irb
irb(main):001:0> system 'rake'
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake.rb:1222:in
`load_rakefile'
=> false
---------------------------

On windows:
---------------------------
D:\temp>rake
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
c:/unix/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1373:in
`load_rakefile'
D:\temp>irb
irb(main):001:0> system 'rake'
=> false
---------------------------

I think I know how this happens and everything (having done quite some c
programming on windows), its just that I think that it breaks
expectations. I hope I could illustrate my point.

kaspar
--
code manufacture & ruby lab at http://www.tua.ch/ruby


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
snacktime  
View profile  
 More options Nov 25 2005, 2:46 pm
Newsgroups: comp.lang.ruby
From: snacktime <snackt...@gmail.com>
Date: Sat, 26 Nov 2005 04:46:55 +0900
Local: Fri, Nov 25 2005 2:46 pm
Subject: Re: system() on windows
On 11/25/05, Damphyr <damp...@freemail.gr> wrote:

Ya I shouldn't be up this late either.  No I didn't pass the block:)

Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaspar Schiess  
View profile  
 More options Nov 25 2005, 3:07 pm
Newsgroups: comp.lang.ruby
From: Kaspar Schiess <e...@space.ch>
Date: Sat, 26 Nov 2005 05:07:23 +0900
Local: Fri, Nov 25 2005 3:07 pm
Subject: Re: system() on windows
A small follow up...

Looks like as soon as you have a pipe in the command, cmd.exe is invoked
correctly: system 'echo | rails'. I came up with this after digging trough
to the actual implementation and nosing around for quite a time ;) .. its
of course nonsensical.

k

--
code manufacture & ruby lab at http://www.tua.ch/ruby


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nobuyoshi nakada  
View profile  
 More options Nov 28 2005, 3:30 am
Newsgroups: comp.lang.ruby
From: nobuyoshi nakada <nobuyoshi.nak...@ge.com>
Date: Mon, 28 Nov 2005 17:30:41 +0900
Local: Mon, Nov 28 2005 3:30 am
Subject: Re: system() on windows
Hi,

At Fri, 25 Nov 2005 06:21:03 +0900,
snacktime wrote in [ruby-talk:167407]:

> I'm trying to figure out why a particular system command is returning
> false on windows.

> This works fine and returns true:

> res = system('dir')

> This returns false with $? being nil:

> res = system('rake')

system('rake.bat')

--
Nobu Nakada


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile  
 More options Nov 28 2005, 4:01 am
Newsgroups: comp.lang.ruby
From: "William James" <w_a_x_...@yahoo.com>
Date: 28 Nov 2005 01:01:26 -0800
Local: Mon, Nov 28 2005 4:01 am
Subject: Re: system() on windows

gregarican wrote:
> Kaspar Schiess wrote:

> > I call ruby scripts by
> >   system('cmd.exe /c rake')

> > Sadly, system seems to be broken many ways on windows.

> > kaspar

> How is this broken? the system() method works directly with the Windows
> shell. And the rake command isn't contained within the Windows shell as
> an internal command. That's why system('dir') works and system('rake')
> doesn't.

No;  system('cal') works.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gregarican  
View profile  
 More options Nov 28 2005, 12:42 pm
Newsgroups: comp.lang.ruby
From: "gregarican" <greg.kuj...@gmail.com>
Date: 28 Nov 2005 09:42:31 -0800
Local: Mon, Nov 28 2005 12:42 pm
Subject: Re: system() on windows

Kaspar Schiess wrote:
> I think I know how this happens and everything (having done quite some c
> programming on windows), its just that I think that it breaks
> expectations. I hope I could illustrate my point.

> kaspar

You're correct. The fact that system() works much differently under
Windows does break expectations. Good illustration!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »