How to pass/return a string to calling program?

Discussion in 'Ruby' started by Tony De, Oct 21, 2010.

  1. Tony De

    Tony De Guest

    Greetings,

    I have a daemon running (linux server) which listens and receives
    service requests from a client, executes the script (which performs the
    services) and then returns a message (returned from the script) back to
    the client.

    So I'm having some trouble getting a message back to the client. In my
    perl scripts a simple "print msg_string" followed by an exit(x) will
    pass the msg_string to the daemon which then sends it back to the
    client. In ruby I've tried without success:

    puts msg_string
    exit

    print msg_string
    exit

    at_exit {print msg_string}
    exit

    at_exit {puts msg_string}

    Any help would be graciously accepted.

    Thanks :)

    tonyd

    --
    Posted via http://www.ruby-forum.com/.
     
    Tony De, Oct 21, 2010
    #1
    1. Advertising

  2. Tony De

    Jeremy Bopp Guest

    On 10/21/2010 3:20 PM, Tony De wrote:
    > Greetings,
    >
    > I have a daemon running (linux server) which listens and receives
    > service requests from a client, executes the script (which performs the
    > services) and then returns a message (returned from the script) back to
    > the client.
    >
    > So I'm having some trouble getting a message back to the client. In my
    > perl scripts a simple "print msg_string" followed by an exit(x) will
    > pass the msg_string to the daemon which then sends it back to the
    > client. In ruby I've tried without success:
    >
    > puts msg_string
    > exit
    >
    > print msg_string
    > exit


    These should definitely work.

    > at_exit {print msg_string}
    > exit
    >
    > at_exit {puts msg_string}


    I haven't had a need to use at_exit before, but I suspect that these
    should also work.

    Have you tried directly running your scripts by hand to confirm that
    they output something at all? If they are printing something, try
    making stdout and stderr synchronous rather than buffered in your scripts:

    $stdout.sync = $stderr.sync = true

    -Jeremy
     
    Jeremy Bopp, Oct 21, 2010
    #2
    1. Advertising

  3. Tony De

    Tony De Guest

    Jeremy Bopp wrote in post #956168:
    > On 10/21/2010 3:20 PM, Tony De wrote:
    >> client. In ruby I've tried without success:
    >>
    >> puts msg_string
    >> exit
    >>
    >> print msg_string
    >> exit

    >
    > These should definitely work.
    >
    >> at_exit {print msg_string}
    >> exit
    >>
    >> at_exit {puts msg_string}

    >
    > I haven't had a need to use at_exit before, but I suspect that these
    > should also work.
    >
    > Have you tried directly running your scripts by hand to confirm that
    > they output something at all? If they are printing something, try
    > making stdout and stderr synchronous rather than buffered in your
    > scripts:
    >
    > $stdout.sync = $stderr.sync = true
    >
    > -Jeremy


    Jeremy

    I am definitely getting output (a simple OK for testing):
    root@smi2-new:/usr/local/services/secure_dir# ./service_prov
    ../config_files/pms.2006.66056308205
    OKroot@smi2-new:/usr/local/services/secure_dir#

    I tried the sync option, but client didnt' get the response. My perl
    script does...

    Thanks so much

    --
    Posted via http://www.ruby-forum.com/.
     
    Tony De, Oct 22, 2010
    #3
  4. Tony De

    Jeremy Bopp Guest

    On 10/21/2010 06:12 PM, Tony De wrote:
    > Jeremy Bopp wrote in post #956168:
    >> On 10/21/2010 3:20 PM, Tony De wrote:
    >>> client. In ruby I've tried without success:
    >>>
    >>> puts msg_string
    >>> exit
    >>>
    >>> print msg_string
    >>> exit

    >>
    >> These should definitely work.
    >>
    >>> at_exit {print msg_string}
    >>> exit
    >>>
    >>> at_exit {puts msg_string}

    >>
    >> I haven't had a need to use at_exit before, but I suspect that these
    >> should also work.
    >>
    >> Have you tried directly running your scripts by hand to confirm that
    >> they output something at all? If they are printing something, try
    >> making stdout and stderr synchronous rather than buffered in your
    >> scripts:
    >>
    >> $stdout.sync = $stderr.sync = true
    >>
    >> -Jeremy

    >
    > Jeremy
    >
    > I am definitely getting output (a simple OK for testing):
    > root@smi2-new:/usr/local/services/secure_dir# ./service_prov
    > ../config_files/pms.2006.66056308205
    > OKroot@smi2-new:/usr/local/services/secure_dir#
    >
    > I tried the sync option, but client didnt' get the response. My perl
    > script does...


    Are you certain that your Ruby scripts are even running? What is the
    exit code your server gets back from running the scripts, and is that
    result expected? Do you have any way to independently confirm that your
    server is actually running your scripts? If not, you might try
    modifying one of your scripts to have it create an empty file in a well
    known location which you could then check for existence after triggering
    your script to run.

    -Jeremy
     
    Jeremy Bopp, Oct 22, 2010
    #4
  5. Tony De

    Tony De Guest

    Jeremy Bopp wrote in post #956216:
    > On 10/21/2010 06:12 PM, Tony De wrote:
    >>> These should definitely work.
    >>> they output something at all? If they are printing something, try

    >> root@smi2-new:/usr/local/services/secure_dir# ./service_prov
    >> ../config_files/pms.2006.66056308205
    >> OKroot@smi2-new:/usr/local/services/secure_dir#
    >>
    >> I tried the sync option, but client didnt' get the response. My perl
    >> script does...

    >
    > Are you certain that your Ruby scripts are even running? What is the
    > exit code your server gets back from running the scripts, and is that
    > result expected? Do you have any way to independently confirm that your
    > server is actually running your scripts? If not, you might try
    > modifying one of your scripts to have it create an empty file in a well
    > known location which you could then check for existence after triggering
    > your script to run.
    >
    > -Jeremy


    My script is running; I run it from the command line as I develop it. I
    can confirm that the script is doing everything it should. It may be,
    although I don't see how, an issue with the daemon calling the script.
    I'll have to dig from the other direction. I may be missing
    something...

    Thank you

    --
    Posted via http://www.ruby-forum.com/.
     
    Tony De, Oct 22, 2010
    #5
  6. Tony De

    Tony De Guest

    Jeremy Bopp wrote in post #956330:
    > On 10/22/2010 10:24 AM, Tony De wrote:
    >>>

    >> My script is running; I run it from the command line as I develop it. I
    >> can confirm that the script is doing everything it should. It may be,
    >> although I don't see how, an issue with the daemon calling the script.
    >> I'll have to dig from the other direction. I may be missing
    >> something...

    >
    > I'm not sure you understood what I was asking. Can you confirm that the
    > daemon is successfully executing your script? Your script may work when
    > you run it yourself, but your daemon may not be running it at all for
    > one reason or another. What you need to have is a way to verify that
    > your script ran otherwise successfully when invoked by your daemon
    > process.
    >
    > Given that your Perl scripts work as you expect, it's likely that due to
    > a configuration problem somewhere your Ruby scripts are never running
    > when the daemon tries to start them. Maybe ruby is not in your PATH, or
    > perhaps your daemon is trying to invoke the scripts differently than you
    > do on the command line.
    >
    > -Jeremy


    Of course, your right. The script is running, I have it logging to
    syslog as well as the daemon logs it's process. The daemon shows that
    it is successfully running the script and my script log is showing that
    it is running. As well as the provisioned services are properly turned
    on/off/suspended, etc.

    Tony

    --
    Posted via http://www.ruby-forum.com/.
     
    Tony De, Oct 22, 2010
    #6
  7. Tony De

    Jeremy Bopp Guest

    On 10/22/2010 12:23 PM, Tony De wrote:
    > Of course, your right. The script is running, I have it logging to
    > syslog as well as the daemon logs it's process. The daemon shows that
    > it is successfully running the script and my script log is showing that
    > it is running. As well as the provisioned services are properly turned
    > on/off/suspended, etc.


    Perhaps you could send a code snippet showing how your daemon runs your
    Ruby scripts and gathers their output. If that logic is at all
    different from how your Perl scripts are run, you should also include a
    code snippet for running them as well.

    -Jeremy
     
    Jeremy Bopp, Oct 22, 2010
    #7
    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. Rey
    Replies:
    4
    Views:
    10,963
    Roedy Green
    Dec 12, 2003
  2. Greenhorn
    Replies:
    15
    Views:
    833
    Keith Thompson
    Mar 6, 2005
  3. utab
    Replies:
    18
    Views:
    1,664
    Diego Martins
    Apr 27, 2006
  4. Marcpp
    Replies:
    1
    Views:
    789
  5. Xeno Campanoli
    Replies:
    0
    Views:
    231
    Xeno Campanoli
    Feb 13, 2006
Loading...

Share This Page