Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to pass/return a string to calling program?

Reply
Thread Tools

How to pass/return a string to calling program?

 
 
Tony De
Guest
Posts: n/a
 
      10-21-2010
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/.

 
Reply With Quote
 
 
 
 
Jeremy Bopp
Guest
Posts: n/a
 
      10-21-2010
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

 
Reply With Quote
 
 
 
 
Tony De
Guest
Posts: n/a
 
      10-21-2010
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/.

 
Reply With Quote
 
Jeremy Bopp
Guest
Posts: n/a
 
      10-22-2010
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

 
Reply With Quote
 
Tony De
Guest
Posts: n/a
 
      10-22-2010
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/.

 
Reply With Quote
 
Tony De
Guest
Posts: n/a
 
      10-22-2010
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/.

 
Reply With Quote
 
Jeremy Bopp
Guest
Posts: n/a
 
      10-22-2010
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= ASP .Net 1 09-28-2004 12:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier ASP .Net 4 07-29-2004 01:06 PM



Advertisments