Hello,
  I'm having some trouble with a perl script I'm writing.

when I try to execute something on the command line, it
just plain *doesn't work* i've used system & backticks (`).
No luck, when I use (`) i get no output either...

the command is:
system("/sbin/mkfs -t xfs $device"); if (!?) { print "Failed! - $?\n"; }
Failed! 13 It's that simple. I'm using system in other parts of this script and it works fine. I can even verify the system call is working, by creating a wrapper script. like so: (make_fs.pl) -------------------------------------------------------
#!/usr/bin/perl -w my $device = $ARGV[0]; print "I GOT $device !!\n"; system("/sbin/mkfs -t xfs $device"); exit($?);
-------------------------------------------------------- (in the main script) --------------------------------------------------------
#system("/sbin/mkfs -t xfs $device"); system("./make_fs.pl $device"); if (!?) { print "Failed! - $?\n"; }
I GOT /dev/exampledevice0 Failed - 13 -------------------------------------------------------- Same, exit code, and the command never ran. the reason I know this is because. if, on the command line, I run that exact same command: # /sbin/mkfs -t xfs /dev/exampledevice0 the program formats it, if it had already been formatted it would ask for me to do a --force. So this is the first time it's been formatted. the script _is_ running as root. and when I print the $! output, it just says "illegal seek". now, if I use backticks (`) instead, this is what happens:
#system("/sbin/mkfs -t xfs $device"); #system("./make_fs.pl $device"); print `/sbin/mkfs -t xfs $device`; if (!?) { print "Failed! - $?\n"; }
Failed! - 13 (no output from the first print) I have been coding in perl for over 2 years and never had this problem before. Any help GREATLY appreciated! - Nick

In reply to calling an external program, from within a perl script by nick

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.