Using system to echo "hello world" gives SystemStackError

I can’t fathom this error regarding the stack:

thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ cat build.rb
require ‘compile’

compile
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ cat compile.rb
def compile
system(echo compile)
end
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ ruby build.rb
./compile.rb:2: warning: parenthesize argument(s) for future version
./compile.rb:2:in compile': stack level too deep (SystemStackError) from ./compile.rb:2:incompile’
from build.rb:4
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$

thanks,

Thufir

On Wednesday 19 March 2008, Thufir wrote:

def compile

thanks,

Thufir

When you first call the ‘compile’ method, ruby tries to execute the line

system(echo compile)

which is interpreted as:

system(echo(compile))

Now ruby needs to evaluate the arguments to the system method. It sees a
single argument, that is the return value of the echo method called with
the
result of a call to the compile method. The first thing it needs to do
is get
the return value of the compile method. But the compile method calls the
compile method again, and so on, which causes infinite recursion and the
error
message you see.

A simpler example is this:

def my_method
my_method
end

Of course, this also cause an infinite recursion and a SystemStackError.

Back to your compile method. My guess is that you wanted to execute the
shell
command echo with argument ‘compile’. If this is true, you need to pass
a
string to system:

system(“echo compile”)

I hope this helps

Stefano

On Wed, Mar 19, 2008 at 5:00 AM, Thufir [email protected] wrote:

def compile

thanks,

Thufir

I don’t know anything about compile. But with #system, I think you
are supposed to have the parameter in quotes.

Right now, your function is recursive with no exit.

Todd

On Wed, 19 Mar 2008 20:13:43 +0900, Todd B. wrote:

I don’t know anything about compile. But with #system, I think you are
supposed to have the parameter in quotes.

Right now, your function is recursive with no exit.

Yes, I’m kinda sorry that I posted that question. It’s always like
that,
if I didn’t post it then I would’ve spent a long time figuring it out,
but if I post then I often get it fixed fairly quickly!

Please do comment on the “right” way to do this, keeping in mind that
it’s partly a way of learning ruby:

thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ cat build.rb
require ‘clean’
require ‘compile’
require ‘run’

clean
compile
run
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ cat clean.rb
def clean
puts “cleaning all class files…”

    system("rm *.class -fv")

end
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ cat compile.rb
def compile
puts “compiling…”
system(“javac HelloWorldApp.java”)
end
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ cat run.rb
def run
puts “running…”
system(“java HelloWorldApp”)
end
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$ ruby build.rb
cleaning all class files…
removed `HelloWorldApp.class’
compiling…
running…
Hello World!
thufir@arrakis:~/sun_tutorial$

thanks,

Thufir

On Wed, 19 Mar 2008 20:10:09 +0900, Stefano C. wrote:

A simpler example is this:

def my_method
my_method
end

An interesting foray into recursion, I had no idea how to interpret that
error, but now have some idea :slight_smile:

Keeping in mind that I’m a beginner ruby-ist, how should I go about
creating a manifest for a java jar? I believe there’s an “automatic”
option, but I’m not positive.

Does it make sense to create a text file from within ruby, then
“include”
that text file as the manifest when doing the jar command? Seems mildly
fragile. IIRC ant automagically takes care of the manifest, so perhaps
I’ll have to create something like that.

I know of raven, but prefer to do it this way for now, it’s a good
impetus to learn some ruby!

thanks for the help,

Thufir

On Wed, Mar 19, 2008 at 5:29 AM, Thufir [email protected] wrote:

but if I post then I often get it fixed fairly quickly!
require ‘compile’

end
removed `HelloWorldApp.class’

thanks,

Thufir

Looks just fine.

I’m not sure, but if all your required files are to solely work with
cleaning and building code, then maybe they should sit inside a module
in one file.

Just a thought.

Obviously, every person has their own best way to approach it.

Todd

On Wed, 19 Mar 2008 20:49:51 +0900, Todd B. wrote:

Looks just fine.

I’m not sure, but if all your required files are to solely work with
cleaning and building code, then maybe they should sit inside a module
in one file.

Just a thought.

Obviously, every person has their own best way to approach it.

Thanks, that’s exactly the type of feedback I was soliciting!

-Thufir