[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to run script file using system command

Dhiraj Girdhar

4/26/2007 6:04:00 AM

Hi,
I am trying to run a script file using system command, but it is not
working.

Code... test.rb

abc = system(". /export/home/dhiraj/scriptfile.sh")
puts abc

The value of abc is false.

Please tell me why script file is not running?

Dhiraj

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

10 Answers

Alex Gutteridge

4/26/2007 6:26:00 AM

0

On 26 Apr 2007, at 15:04, Dhiraj Girdhar wrote:

> Hi,
> I am trying to run a script file using system command, but it is not
> working.
>
> Code... test.rb
>
> abc = system(". /export/home/dhiraj/scriptfile.sh")
> puts abc
>
> The value of abc is false.
>
> Please tell me why script file is not running?

If that is really what you ran then you have a space in your command.

Alex Gutteridge

Bioinformatics Center
Kyoto University



Dhiraj Girdhar

4/26/2007 6:33:00 AM

0

Alex Gutteridge wrote:
> On 26 Apr 2007, at 15:04, Dhiraj Girdhar wrote:
>
>>
>> Please tell me why script file is not running?
>
> If that is really what you ran then you have a space in your command.
>
> Alex Gutteridge
>
> Bioinformatics Center
> Kyoto University

Please tell me if i have a script file say scriptfile, then how i can
run that file using ruby.
Please explaain with example.

Dhiraj

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

Abhijit Gadgil

4/26/2007 6:47:00 AM

0

Hi,Please see below.On 4/26/07, Dhiraj Girdhar <dgirdhar@arcot.com> wrote:> Alex Gutteridge wrote:> > On 26 Apr 2007, at 15:04, Dhiraj Girdhar wrote:> >> >>> >> Please tell me why script file is not running?> >> > If that is really what you ran then you have a space in your command.> >> > Alex Gutteridge> >> > Bioinformatics Center> > Kyoto University>> Please tell me if i have a script file say scriptfile, then how i can> run that file using ruby.> Please explaain with example.(assuming Unixish system)bash$ cat > tp "hello world!"Ctrl.d (Pressing Ctrl and d key)bash$ ruby -e 'system("ruby", "t")'hello world!bash$> Dhiraj>> --> Posted via http://www.ruby-forum.com/.... ??????[ written in http://www.pa.../... ][ http://www.pa... ]

Alex Gutteridge

4/26/2007 6:49:00 AM

0

On 26 Apr 2007, at 15:33, Dhiraj Girdhar wrote:

> Alex Gutteridge wrote:
>> On 26 Apr 2007, at 15:04, Dhiraj Girdhar wrote:
>>
>>>
>>> Please tell me why script file is not running?
>>
>> If that is really what you ran then you have a space in your command.
>>
>> Alex Gutteridge
>>
>> Bioinformatics Center
>> Kyoto University
>
> Please tell me if i have a script file say scriptfile, then how i can
> run that file using ruby.
> Please explaain with example.

I was a bit terse with my previous answer. I was just pointing out
that you had a space between the initial '.' and the rest of your
command which would cause system() to fail. Here is an example of how
to run a script using system():

[alexg@powerbook]/Users/alexg(5): cat test.sh
#!/bin/sh

echo 'foo'
[alexg@powerbook]/Users/alexg(6): ./test.sh
foo
[alexg@powerbook]/Users/alexg(7): ruby -e "system('./test.sh')"
foo

Alex Gutteridge

Bioinformatics Center
Kyoto University



Dhiraj Girdhar

4/26/2007 6:59:00 AM

0

Alex Gutteridge wrote:
> On 26 Apr 2007, at 15:33, Dhiraj Girdhar wrote:
>
>>> Bioinformatics Center
>>> Kyoto University
>>
>> Please tell me if i have a script file say scriptfile, then how i can
>> run that file using ruby.
>> Please explaain with example.
>
> I was a bit terse with my previous answer. I was just pointing out
> that you had a space between the initial '.' and the rest of your
> command which would cause system() to fail. Here is an example of how
> to run a script using system():
>
> [alexg@powerbook]/Users/alexg(5): cat test.sh
> #!/bin/sh
>
> echo 'foo'
> [alexg@powerbook]/Users/alexg(6): ./test.sh
> foo
> [alexg@powerbook]/Users/alexg(7): ruby -e "system('./test.sh')"
> foo
>
> Alex Gutteridge
>
> Bioinformatics Center
> Kyoto University

I tried above in following manner, but i got following error.
1) I created one script file name :sample
with following data
#!/bin/sh

echo 'foo'

Then i created a test.rb file with following code

abc = system("./sample")
puts $?
puts abc

Note: Both files are in same folder.

when i executed the test file with following command

ruby test.rb

I got following result

test.rb:2: warning: Insecure world writable dir
/opt/oracle/product/10.2.0/client_1/bin, mode 040777
32512
false

Please try the same.
OS : Solaris
Ruby Version: 1.8.5


Dhiraj

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

Björn Paetzel

4/26/2007 7:21:00 AM

0

Dhiraj Girdhar schrieb:

> #!/bin/sh
>
> echo 'foo'
>
> Then i created a test.rb file with following code
>
> abc = system("./sample")
> puts $?
> puts abc
>
> Note: Both files are in same folder.

So, when do you change the permissions on the script so it can be executed?

Alex Gutteridge

4/26/2007 7:45:00 AM

0

On 26 Apr 2007, at 15:59, Dhiraj Girdhar wrote:

> Alex Gutteridge wrote:
>> On 26 Apr 2007, at 15:33, Dhiraj Girdhar wrote:
>>
>>>> Bioinformatics Center
>>>> Kyoto University
>>>
>>> Please tell me if i have a script file say scriptfile, then how i
>>> can
>>> run that file using ruby.
>>> Please explaain with example.
>>
>> I was a bit terse with my previous answer. I was just pointing out
>> that you had a space between the initial '.' and the rest of your
>> command which would cause system() to fail. Here is an example of how
>> to run a script using system():
>>
>> [alexg@powerbook]/Users/alexg(5): cat test.sh
>> #!/bin/sh
>>
>> echo 'foo'
>> [alexg@powerbook]/Users/alexg(6): ./test.sh
>> foo
>> [alexg@powerbook]/Users/alexg(7): ruby -e "system('./test.sh')"
>> foo
>>
>> Alex Gutteridge
>>
>> Bioinformatics Center
>> Kyoto University
>
> I tried above in following manner, but i got following error.
> 1) I created one script file name :sample
> with following data
> #!/bin/sh
>
> echo 'foo'
>
> Then i created a test.rb file with following code
>
> abc = system("./sample")
> puts $?
> puts abc
>
> Note: Both files are in same folder.
>
> when i executed the test file with following command
>
> ruby test.rb
>
> I got following result
>
> test.rb:2: warning: Insecure world writable dir
> /opt/oracle/product/10.2.0/client_1/bin, mode 040777
> 32512
> false
>
> Please try the same.
> OS : Solaris
> Ruby Version: 1.8.5

Sorry, I don't have access to a Solaris machine so I can't reproduce
the error. And I have no idea what a 32512 error code means. Your
code looks fine to me, so I'm not sure what the problem could be.

Good luck.

Alex Gutteridge

Bioinformatics Center
Kyoto University



Ari Brown

4/26/2007 11:24:00 AM

0

On Apr 26, 2007, at 2:04 AM, Dhiraj Girdhar wrote:

> Hi,
> I am trying to run a script file using system command, but it is not
> working.
>
> Code... test.rb
>
> abc = system(". /export/home/dhiraj/scriptfile.sh")
> puts abc
The problem is right here. system doesn't need a puts to be used, so
when you try to puts the value of a block (a block of code, and the
block is abc = system("./export/home/dhiraj/scriptfile.sh")), you get
false. It doesn't have a value. You can just have it say:

system("./export/home/dhiraj/scriptfile.sh")

and it will work.

If this made any sense,
HTH

-------------------------------------------------------|
~ Ari
crap my sig won't fit


Dhiraj Girdhar

4/26/2007 11:29:00 AM

0

Ari Brown wrote:
> On Apr 26, 2007, at 2:04 AM, Dhiraj Girdhar wrote:
>
>> Hi,
>> I am trying to run a script file using system command, but it is not
>> working.
>>
>> Code... test.rb
>>
>> abc = system(". /export/home/dhiraj/scriptfile.sh")
>> puts abc
> The problem is right here. system doesn't need a puts to be used, so
> when you try to puts the value of a block (a block of code, and the
> block is abc = system("./export/home/dhiraj/scriptfile.sh")), you get
> false. It doesn't have a value. You can just have it say:
>
> system("./export/home/dhiraj/scriptfile.sh")
>
> and it will work.
>
> If this made any sense,
> HTH
>
> -------------------------------------------------------|
> ~ Ari
> crap my sig won't fit

Hello Ari

Here variable abc is ued to collect the return value of system command
as
system command returns some value.

Return value of system states that whether the command executed
successfully or not.

Dhiraj

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

Ari Brown

4/28/2007 11:55:00 PM

0

On Apr 26, 2007, at 7:29 AM, Dhiraj Girdhar wrote:
<snipxor>

>> The problem is right here. system doesn't need a puts to be used, so
>> when you try to puts the value of a block (a block of code, and the
>> block is abc = system("./export/home/dhiraj/scriptfile.sh")), you get
>> false. It doesn't have a value. You can just have it say:
>>
>> system("./export/home/dhiraj/scriptfile.sh")
>>
>> and it will work.
> Hello Ari
>
> Here variable abc is ued to collect the return value of system command
> as
> system command returns some value.
>
> Return value of system states that whether the command executed
> successfully or not.

Ohhhhhhh! Well now THAT makes sense. In that case, i retract my
comment and fully commit myself to ruby indulgence and education.

Pshhh, not like I already haven't/
---------------------------------------------------------------|
~Ari
"I don't suffer from insanity. I enjoy every minute of it" --1337est
man alive