[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Processes and Portability

Name Name

7/11/2006 3:58:00 PM

I would like to run a process concurrently (thus if the process goes to
sleep or runs forever, I can still run other code from my main process)
and have all standard out of that process be put into a text file. I
would also like this code to be portable. And finally, I would like to
be able to kill this process at any time (So I will need the pid)

This thus eliminates the use of fork. Also, I have tried:

a=IO.popen("program > logfile"), but on Windows this creates two
processes, cmd.exe and program. a.pid only gives the pid of cmd.exe.
And the behavior on *nix seems to be just the program (although I can be
wrong).

So I require portability in that sense.

Is this possible?

thanks

--
Posted via http://www.ruby-....

18 Answers

Ara.T.Howard

7/11/2006 4:32:00 PM

0

khaines

7/11/2006 4:46:00 PM

0

Name Name

7/11/2006 6:21:00 PM

0

I know this sounds nieve, but is there a way to do what I want without
requiring an external gem, and without that extremely long code on the
secnod post. I would really prefer just to use native ruby.

Be able to concurrently run a process (that could potentially block
forever or run forever) written in another language and having the
ability to stop it at anytime.

a=IO.popen (program_name)
Process.kill(9,a.pid)

works, but it won't log to a file

a=IO.popen(program_name > logfile)
Process.kill(9, a.pid)

spawns two processes and does not kill both.

I need something to be able to do the latter.

thanks

--
Posted via http://www.ruby-....

Name Name

7/11/2006 7:20:00 PM

0

or is there is a way to directly write to a file using IO.popen.

--
Posted via http://www.ruby-....

Harmen Schut

7/11/2006 7:23:00 PM

0

Name Name wrote:
> ...
>
> a=IO.popen(program_name > logfile)
> Process.kill(9, a.pid)
>
> spawns two processes and does not kill both.
>
> I need something to be able to do the latter.
>
> thanks

What about:

a=IO.popen("#{program_name} > #{logfile}")
Process.kill(9, a.pid)

Don't know if that works on MSWindows.

Harmen

--
Posted via http://www.ruby-....

Name Name

7/11/2006 7:28:00 PM

0

I don't understand how that is different than:
a=IO.popen(program_name > logfile)
Process.kill(9, a.pid)




Harmen Schut wrote:
> Name Name wrote:
>> ...
>>
>> a=IO.popen(program_name > logfile)
>> Process.kill(9, a.pid)
>>
>> spawns two processes and does not kill both.
>>
>> I need something to be able to do the latter.
>>
>> thanks
>
> What about:
>
> a=IO.popen("#{program_name} > #{logfile}")
> Process.kill(9, a.pid)
>
> Don't know if that works on MSWindows.
>
> Harmen


--
Posted via http://www.ruby-....

Harmen Schut

7/11/2006 7:34:00 PM

0

It is one String argument (a command line) instead of an expression
(compairing two String variables?)

Harmen

Name Name wrote:
> I don't understand how that is different than:
> a=IO.popen(program_name > logfile)
> Process.kill(9, a.pid)
>
>
>
>
> Harmen Schut wrote:
>> Name Name wrote:
>>> ...
>>>
>>> a=IO.popen(program_name > logfile)
>>> Process.kill(9, a.pid)
>>>
>>> spawns two processes and does not kill both.
>>>
>>> I need something to be able to do the latter.
>>>
>>> thanks
>>
>> What about:
>>
>> a=IO.popen("#{program_name} > #{logfile}")
>> Process.kill(9, a.pid)
>>
>> Don't know if that works on MSWindows.
>>
>> Harmen


--
Posted via http://www.ruby-....

Name Name

7/11/2006 7:36:00 PM

0

I'm sorry if my previous thing was confusing, but it was actually:

IO.popen("program_name > logfile").


Harmen Schut wrote:
> It is one String argument (a command line) instead of an expression
> (compairing two String variables?)
>
> Harmen
>
> Name Name wrote:
>> I don't understand how that is different than:
>> a=IO.popen(program_name > logfile)
>> Process.kill(9, a.pid)
>>
>>
>>
>>
>> Harmen Schut wrote:
>>> Name Name wrote:
>>>> ...
>>>>
>>>> a=IO.popen(program_name > logfile)
>>>> Process.kill(9, a.pid)
>>>>
>>>> spawns two processes and does not kill both.
>>>>
>>>> I need something to be able to do the latter.
>>>>
>>>> thanks
>>>
>>> What about:
>>>
>>> a=IO.popen("#{program_name} > #{logfile}")
>>> Process.kill(9, a.pid)
>>>
>>> Don't know if that works on MSWindows.
>>>
>>> Harmen


--
Posted via http://www.ruby-....

Yohanes Santoso

7/11/2006 7:53:00 PM

0

Name Name <exl2@cornell.edu> writes:

> a=IO.popen("program > logfile"), but on Windows this creates two
> processes, cmd.exe and program. a.pid only gives the pid of cmd.exe.
> And the behavior on *nix seems to be just the program (although I can be
> wrong).

The behaviour in *nix depends on your /bin/sh. Some shells gives the
child's pid, other gives the pid of itself.

pdksh gives the pid of itself.
bash gives the pid of the child (the behaviour you wanted).
Don't know about other shells.

The lesson here, you can't get the pid of the child consistently
unless you do the forking yourself.

YS

Harmen Schut

7/11/2006 7:59:00 PM

0

On Linux that should work if program 'progam_name' produces output and
file 'logfile' is writable. One of the two processes you mentioned is an
intermediate shell by the way.

Harmen

Name Name wrote:
> I'm sorry if my previous thing was confusing, but it was actually:
>
> IO.popen("program_name > logfile").
>
> ...

--
Posted via http://www.ruby-....