How to pass/return a string to calling program?

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 :slight_smile:

tonyd

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 B. 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):
[email protected]:/usr/local/services/secure_dir# ./service_prov
…/config_files/pms.2006.66056308205
[email protected]:/usr/local/services/secure_dir#

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

Thanks so much

Jeremy B. 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
[email protected]:/usr/local/services/secure_dir# ./service_prov
…/config_files/pms.2006.66056308205
[email protected]:/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

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
[email protected]:/usr/local/services/secure_dir# ./service_prov
…/config_files/pms.2006.66056308205
[email protected]:/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

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

Jeremy B. 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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs