How to pass/return a string to calling program?

T

Tony De

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
 
J

Jeremy Bopp

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
 
T

Tony De

Jeremy Bopp wrote in post #956168:
These should definitely work.


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
 
J

Jeremy Bopp

Jeremy Bopp wrote in post #956168:

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
 
T

Tony De

Jeremy Bopp wrote in post #956216:
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
 
T

Tony De

Jeremy Bopp wrote in post #956330:
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
 
J

Jeremy Bopp

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top