using system to echo "hello world" gives SystemStackError

T

Thufir

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:in `compile'
from build.rb:4
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$




thanks,

Thufir
 
S

Stefano Crocco

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:in `compile'
from build.rb:4
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$




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
 
T

Todd Benson

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:in `compile'
from build.rb:4
thufir@arrakis:~/sun_tutorial$
thufir@arrakis:~/sun_tutorial$




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
 
T

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.


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
 
T

Todd Benson

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

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
 
T

Thufir

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 :)

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
 
T

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.



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


-Thufir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top