# System() vs. commandline?

**URL:** <https://www.ruby-forum.com/t/system-vs-commandline/59274>\
**Category:** Ruby\
**Created:** [May 3, 2006, 3:13am UTC](https://www.ruby-forum.com/t/system-vs-commandline/59274 "2006-05-03T03:13:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 3, 2006, 3:13am UTC](https://www.ruby-forum.com/t/system-vs-commandline/59274/1 "2006-05-03T03:13:27Z")

</div>

I have a C program that processes text files. When I run it from the  
commandline, it works fine. But if I run it via Ruby with  
‘system(“textproc input output”)’ that output file usually gets  
truncated near its end. The docs state:

“one of the exec(2) system calls is used, so the running command may  
inherit some of the environment of the original program (including open  
file descriptors)”

Is there some setting for Ruby which could be causing this problem -  
such as a memory limit? I don’t get any error messages whatsoever. I’ve  
also tried exec() and popen(), with the same results.

Thanks,  
Joe  
Redhat FC4  
Ruby 1.8.4

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 3, 2006, 4:08am UTC](https://www.ruby-forum.com/t/system-vs-commandline/59274/2 "2006-05-03T04:08:42Z")

</div>

I rewrote the script in PHP and it all works fine. If anybody has any  
insights or guesses why Ruby causes it to choke, please feel free!

Joe

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 3, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/system-vs-commandline/59274/3 "2006-05-03T20:39:26Z")

</div>

Dean W. wrote:

> When you say “truncated near the end”, is that the last line of text  
> that gets chopped? Last 1 or few characters?

No, it’s the last page or so of text that gets truncated, in the middle  
of paragraphs.

> Does the C program close  
> all open file handles, etc.?

AFAIK. I didn’t write it. But it works fine with everything else besides  
Ruby.

> Also, what platform are you on?

Redhat FC4

Joe

> dean
> 
> –  
> Dean W.  
> [http://www.aspectprogramming.com](http://www.aspectprogramming.com)  
> [http://www.newaspects.com](http://www.newaspects.com)  
> [http://www.contract4j.org](http://www.contract4j.org)

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 3, 2006, 7:06pm UTC](https://www.ruby-forum.com/t/system-vs-commandline/59274/4 "2006-05-03T19:06:19Z")

</div>

When you say “truncated near the end”, is that the last line of text  
that gets chopped? Last 1 or few characters? Does the C program close  
all open file handles, etc.? Also, what platform are you on?

dean

–  
Dean W.  
[http://www.aspectprogramming.com](http://www.aspectprogramming.com)

> **[NewAspects.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=newaspects.com)**
>
> Premium domains add authority to your site. Transparent pricing. 1 year WHOIS privacy included. 30-day money back guarantee.

[http://www.contract4j.org](http://www.contract4j.org)
