Trouble with system() on SunOS

Discussion in 'Ruby' started by galevsky, May 16, 2007.

  1. galevsky

    galevsky Guest

    Hi all,

    I am facing trouble with a system call on one of my tool: XmlChecker


    * The script
    -- test.rb
    system "echo 'Here is the tool'"
    system "which XmlChecker"
    system "echo '$PATH def'"
    system "echo $PATH"
    system "XmlChecker -V"

    * The execution:

    [578] XmlChecker -V
    v1.9
    [579] ruby -W0 test.rb
    Here is the tool
    /projects/fqdbdatamig/tools/prod/bin//XmlChecker
    $PATH def
    [...]:/projects/fqdbdatamig/tools/prod/bin/:.
    [580]

    Note that I ran the script with -W0 to avoid "warning: Insecure world
    writable dir /teams/com_fqd_dev/tools, mode 040777" messages.

    What is wrong with that ? The system call does not read the $PATH var ?
    Why 'echo' ran well ?

    Many thanks for your support,

    Gal'

    --
    Posted via http://www.ruby-forum.com/.
    galevsky, May 16, 2007
    #1
    1. Advertising

  2. galevsky

    Galevsky Gal Guest

    Doug Phillips wrote:
    >>
    >>
    >> Insecure world writable dir /teams/com_fqd_dev/tools, mode
    >> 040777" messages.
    >>
    >> What is wrong with that ? The system call does not read the
    >> $PATH var ?
    >> Why 'echo' ran well ?

    > The first echo of $PATH has $PATH surrounded by single quotes; the shell
    > will not evaluate $PATH, instead taking it literally. Encapsulate it in
    > double quotes (you'll need to escape them so they execute properly), and
    > it should work as expected.
    >
    > irb(main):003:0> system "echo \"$PATH def\""
    > /usr/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/php/bin:/usr/ccs/b
    > in:/usr/local/mysql/bin def
    > => true
    >
    > (The above was run on a Solaris 10 machine)


    LOL, i am not facing a problem with a print of $PATH var, since I know
    how to do and did it on the next line, what is wrong is the
    execution....


    [578] XmlChecker -V
    v1.9
    [579] ruby -W0 test.rb
    Here is the tool
    /projects/fqdbdatamig/tools/prod/bin//XmlChecker
    $PATH def
    [...]:/projects/fqdbdatamig/tools/prod/bin/:.
    [580]

    Well, when I run 'XmlChecker -V' in a shell, it generates the output
    'v1.9'.
    When I try to run it through out a ruby script 'system "XmlChecker -V"',
    nothing happens, like it was not executed. Is 'Xmlchecker -V' not
    executed ? Why ? the $PATH var shows it knows where to find the tool
    XmlChecker.

    Thanks for your support,

    Gal'

    --
    Posted via http://www.ruby-forum.com/.
    Galevsky Gal, May 31, 2007
    #2
    1. Advertising

  3. On 31.05.2007 16:03, Galevsky Gal wrote:
    > Doug Phillips wrote:
    >>>
    >>> Insecure world writable dir /teams/com_fqd_dev/tools, mode
    >>> 040777" messages.
    >>>
    >>> What is wrong with that ? The system call does not read the
    >>> $PATH var ?
    >>> Why 'echo' ran well ?

    >> The first echo of $PATH has $PATH surrounded by single quotes; the shell
    >> will not evaluate $PATH, instead taking it literally. Encapsulate it in
    >> double quotes (you'll need to escape them so they execute properly), and
    >> it should work as expected.
    >>
    >> irb(main):003:0> system "echo \"$PATH def\""
    >> /usr/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/php/bin:/usr/ccs/b
    >> in:/usr/local/mysql/bin def
    >> => true
    >>
    >> (The above was run on a Solaris 10 machine)

    >
    > LOL, i am not facing a problem with a print of $PATH var, since I know
    > how to do and did it on the next line, what is wrong is the
    > execution....
    >
    >
    > [578] XmlChecker -V
    > v1.9
    > [579] ruby -W0 test.rb
    > Here is the tool
    > /projects/fqdbdatamig/tools/prod/bin//XmlChecker
    > $PATH def
    > [...]:/projects/fqdbdatamig/tools/prod/bin/:.
    > [580]
    >
    > Well, when I run 'XmlChecker -V' in a shell, it generates the output
    > 'v1.9'.
    > When I try to run it through out a ruby script 'system "XmlChecker -V"',
    > nothing happens, like it was not executed. Is 'Xmlchecker -V' not
    > executed ? Why ? the $PATH var shows it knows where to find the tool
    > XmlChecker.
    >
    > Thanks for your support,


    Since you do not need shell interpolation I'd use the array form of system:

    system "XmlChecker", "-V"

    Frankly, I am not sure why you are not seeing anything. Maybe it has
    something to do with output buffering or such. As an alternative you
    could do

    p `XmlChecker -V`

    to see whether there is any output.

    Another reason why you don't see anything is that XmlChecker might print
    the version to stderr. To verify do this at a shell prompt

    XmlChecker -V 2> /dev/null

    If you do not see the version then it's printed to stderr.

    Kind regards

    robert
    Robert Klemme, May 31, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nishi Bhonsle
    Replies:
    17
    Views:
    911
    Nishi Bhonsle
    Sep 27, 2004
  2. Billy Patton

    testing on 64/32 Linux/SunOS

    Billy Patton, Apr 26, 2005, in forum: C++
    Replies:
    0
    Views:
    461
    Billy Patton
    Apr 26, 2005
  3. Berthold =?iso-8859-15?q?H=F6llmann?=

    compiling _tkinter.so (2.3) on SunOS 5.8

    Berthold =?iso-8859-15?q?H=F6llmann?=, Aug 26, 2003, in forum: Python
    Replies:
    0
    Views:
    335
    Berthold =?iso-8859-15?q?H=F6llmann?=
    Aug 26, 2003
  4. Replies:
    2
    Views:
    1,703
    gaool
    Sep 16, 2004
  5. gaool

    Buffer problem on SunOS

    gaool, Nov 22, 2004, in forum: Python
    Replies:
    1
    Views:
    559
    Donn Cave
    Nov 22, 2004
Loading...

Share This Page