# Using system to echo "hello world" gives SystemStackError

**URL:** <https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357>\
**Category:** Ruby\
**Created:** [March 19, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357 "2008-03-19T12:00:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/1 "2008-03-19T12:00:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/2 "2008-03-19T12:10:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 12:14pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/3 "2008-03-19T12:14:32Z")

</div>

On Wed, Mar 19, 2008 at 5:00 AM, Thufir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/4 "2008-03-19T12:30:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 12:56pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/5 "2008-03-19T12:56:01Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 12:51pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/6 "2008-03-19T12:51:28Z")

</div>

On Wed, Mar 19, 2008 at 5:29 AM, Thufir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [March 19, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/using-system-to-echo-hello-world-gives-systemstackerror/132357/7 "2008-03-19T19:46:30Z")

</div>

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
