What tilly and Zaxo have said is correct, you get the return staus of a shell. You're calling perl "foo&", and that's a shell syntax for running a process in the background. Only in special cases does system run things directly from perl and bypass the shell, this is not one of them.

That said, the problem at hand can be solved in a few ways. One is the double open as tilly suggested. Another, more complicated, is to use fork and exec yourself. A third would be to use short-circuting in your system call, something like

system(q(fred & barney || true ));
Which means
run fred in the background, and then try to run barney (no need to background barney and it wouldn't allow the trick anyhow). If barney exits with 0 status echo runs and we have successful termination indicated by true's return value of 0.
Use true, false, && and || as necessary to achieve the desired results.

UPDATE: You shouldn't even need the logic actually, you can twiddle the return code as needed within perl itslef. In short, loose the second ampersand :-P.

--
I'm not belgian but I play one on TV.


In reply to Re: multi-command sytem call by belg4mit
in thread multi-command sytem call by water

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.