Ask a Question related to Ruby, Design and Development.
-
Dan #1
Ruby launching system apps?
I have a UNIX machine and I want a ruby app that can launch UNIX commands
like awk or sed...how would I implement this?
use Shell.new?
Dan Guest
-
Not launching -- unable to continue because of hardware or system error
What would cause Photoshop 6.0.1 to give me an error message, right after the loading fonts initializing screen, that says "Unable to continue... -
all .NET apps cause System.Security.Policy.PolicyException
I was testing some configuration options with Framework Configuration tool and eventually something went wrong in .NET security. Now cannot do... -
Launching Apps
I have read through the blurb on opening an exe from director, however, it gives me a script error when trying this. I have tried all of the... -
Launching Explorer 5.1.7 crashes my system
In article <dennmac-ya02408000R0410031745380001@NNTP.InfoAve.Net>, Dennis McGee <dennmac@InfoAveObstacle.Net> wrote: If you have Disk Warrior,... -
launching apps from expansion cards
Are there any 3rd party launchers which allow launching apps from ANY directory on expansion cards and not only from the default /Palm/Launcher... -
Gennady #2
Re: Ruby launching system apps?
The simplest way is to use "system" or `` (you can use Shell too, of
course). ôhe best way is to implement in Ruby all you do with awk and sed,
as it has (almost) everything those utilities offer.
Before I found Ruby, my favorite combination was sh/awk/sed. Now I do
everything of that kind in Ruby, however knowledge and long experience with
those utilities help me a lot, especially with regexp stuff.
Gennady.
----- Original Message -----
From: "Dan" <falseflyboy@yahoo.comNONO>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Monday, August 25, 2003 10:25 AM
Subject: Ruby launching system apps?
> I have a UNIX machine and I want a ruby app that can launch UNIX commands
> like awk or sed...how would I implement this?
>
> use Shell.new?
>
>
>
>
Gennady Guest
-
mgarriss #3
Re: Ruby launching system apps?
Dan wrote:
`cat some_file` # returns string of stdout>I have a UNIX machine and I want a ruby app that can launch UNIX commands
>like awk or sed...how would I implement this?
>
>use Shell.new?
>
>
system 'cat some_file' # returns success (true/false)
exec 'cat some_file' # replaces current process
popen 'cat some_file' # returns IO object connected to stdin and stdout
require 'open3'
Open3.popen3 'cat some_file' # returns [in,out,err]
mgarriss Guest
-
Mark Wilson #4
Re: Ruby launching system apps?
On Monday, August 25, 2003, at 01:25 PM, Dan wrote:
I've found that when you have a program that makes use of UNIX commands> I have a UNIX machine and I want a ruby app that can launch UNIX
> commands
> like awk or sed...how would I implement this?
>
> use Shell.new?
within various classes and methods that system and `` calls can lead to
synchronization problems -- and that such problems can be solved by
using the Shell#transact method.
Here's an example:
class Document
Shell.def_system_command("lynx")
attr_reader :path
def initialize(path)
@path = path
end
def html_to_text_stdout
# the following line is needed because @path is not in the scope of the
transact block below
path = @path
html_to_text = String.new
shell = Shell.new
shell.transact do
html_to_text = (shell.lynx("-dump", path)).to_s
end
html_to_text
end
end
I agree with Gennady that you will frequently be better off using
native Ruby classes and methods for many things, particularly in-memory
string manipulation, even if comparable tools are available through a
Unix command.
Regards,
Mark
Mark Wilson Guest
-
Mark J. Reed #5
Re: Ruby launching system apps?
On Monday, August 25, 2003, at 01:25 PM, Dan wrote:
The Shell module lets you invoke UNIX commands, but bear in mind> I have a UNIX machine and I want a ruby app that can launch UNIX
> commands like awk or sed...how would I implement this?
that doing so is inefficient, not portable to non-UNIX machines,
and likely to cause thread synchronization issues. Ruby itself can
do everything awk and sed can do without having to resort to
running external programs.
-Mark
Mark J. Reed Guest
-
Mark Wilson #6
Re: Ruby launching system apps?
On Monday, August 25, 2003, at 05:05 PM, Mark J. Reed wrote:
Avoid premature optimization. If the inefficiency is a problem,> On Monday, August 25, 2003, at 01:25 PM, Dan wrote:>>> I have a UNIX machine and I want a ruby app that can launch UNIX
>> commands like awk or sed...how would I implement this?
> The Shell module lets you invoke UNIX commands, but bear in mind
> that doing so is inefficient,
implement in Ruby. If it is still a problem, extend Ruby with C.
True. The universe of Unix machines is pretty large (including Mac OS> not portable to non-UNIX machines,
X). I don't know about Windows with cygwin.
The Shell#transact method will handle synchronization.> and likely to cause thread synchronization issues.
True. 'awk' and 'sed' are the least likely candidates, in my opinion,> Ruby itself can
> do everything awk and sed can do without having to resort to
> running external programs.
> [snip]
for wrapping in the Shell class. However, if you have a shell script
with functionality you want to use in a Ruby program that you don't
want to spend the time reimplementing in Ruby, the Shell class may be
your best bet, at least initially.
Regards,
Mark
Mark Wilson Guest
-
dblack@superlink.net #7
Re: Ruby launching system apps?
Hi --
On Tue, 26 Aug 2003, Lothar Scholz wrote:
Then it isn't premature :-)>>> > Avoid premature optimization. If the inefficiency is a problem,
> I hear this a thousand times, but this makes it not more truth.
> You should only avoid optimization if it results in a more complex
> structure. This is only in a few cases the reality. Often an optimal
> datastructure doesn't take longer to debug or to write.
David
--
David Alan Black
home: [email]dblack@superlink.net[/email]
work: [email]blackdav@shu.edu[/email]
Web: [url]http://pirate.shu.edu/~blackdav[/url]
dblack@superlink.net Guest
-
Bermejo, Rodrigo #8
Re: Ruby launching system apps?
>
>> on ruby 1.6.8>>
>>
>> I agree with Gennady that you will frequently be better off using
>> native Ruby classes and methods for many things, particularly
>> in-memory string manipulation, even if comparable tools are available
>> through a Unix command.
>>
>> Regards,
>>
>> Mark
>>
>
> time ruby -p -e 'gsub("sed","ruby")' file_with_1000000_sed_lines
> 7.61s user 2.02s system 35% cpu 27.161 total
>
> time sed s/sed/ruby/g file_with_1000000_sed_lines
> 2.05s user 1.71s system 32% cpu 11.571 total
>
> ...I expected other results...but (I hope) it's improved on 1.8 (
> I could not test it now on 1.8 )
>
> -r.
>
>
>
>
>
>
Bermejo, Rodrigo Guest
-
Florian Frank #9
Re: Ruby launching system apps?
On 2003-08-26 23:03:55 +0900, Bermejo, Rodrigo wrote:
I don't think that it is fair to compare ruby with sed because Ruby's> on ruby 1.6.8
>
> time ruby -p -e 'gsub("sed","ruby")' file_with_1000000_sed_lines
> 7.61s user 2.02s system 35% cpu 27.161 total
>
> time sed s/sed/ruby/g file_with_1000000_sed_lines
> 2.05s user 1.71s system 32% cpu 11.571 total
>
> ...I expected other results...but (I hope) it's improved on 1.8 (
> I could not test it now on 1.8 )
regular expressions are better than extended REs (ERE) while sed seems
to support at most basic regular expressions (BRE). If you only need a
subset it's no wonder that sed is faster and a good choice for
optimization. Compared to Perl's RE Ruby is not too bad and I suppose
that Perl's RE are very highly optimized for speed.
[flori@lambda big](130)$ echo sed: ; time sed s/sed/ruby/g sed.txt > /dev/null ; echo ruby: ; time ruby -p -e 'gsub(/sed/,%q/ruby/)' sed.txt > /dev/null ; echo perl: ; time perl -p -e 's/sed/ruby/g' sed.txt > /dev/null
sed:
real 0m1.793s
user 0m1.670s
sys 0m0.016s
ruby:
real 0m13.141s
user 0m11.953s
sys 0m0.131s
perl:
real 0m9.773s
user 0m9.109s
sys 0m0.104s
[flori@lambda flori](0)$ ruby -e 'puts "%.2f" % ((11.953 / 9.109 - 1) * 100)'
31.22
Perl is ca. 30% faster than Ruby, that's not too much. Given the fact
that in Ruby regular expressions are first class citizens and full
flexed objects after beeing created, while you have to use work arounds
like qr/.../ if you want to pass them around in Perl.
--
It is by the goodness of God that in our country we have those three
unspeakably precious things: freedom of speech, freedom of conscience, and
the prudence never to practice either.
-- Mark Twain, More Tramps Abroad
Florian Frank Guest



Reply With Quote

