How to run script file using system command

D

Dhiraj Girdhar

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
 
A

Alex Gutteridge

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
 
D

Dhiraj Girdhar

Alex said:
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
 
A

Abhijit Gadgil

SGksCgpQbGVhc2Ugc2VlIGJlbG93LgoKT24gNC8yNi8wNywgRGhpcmFqIEdpcmRoYXIgPGRnaXJk
aGFyQGFyY290LmNvbT4gd3JvdGU6Cj4gQWxleCBHdXR0ZXJpZGdlIHdyb3RlOgo+ID4gT24gMjYg
QXByIDIwMDcsIGF0IDE1OjA0LCBEaGlyYWogR2lyZGhhciB3cm90ZToKPiA+Cj4gPj4KPiA+PiBQ
bGVhc2UgdGVsbCBtZSB3aHkgc2NyaXB0IGZpbGUgaXMgbm90IHJ1bm5pbmc/Cj4gPgo+ID4gSWYg
dGhhdCBpcyByZWFsbHkgd2hhdCB5b3UgcmFuIHRoZW4geW91IGhhdmUgYSBzcGFjZSBpbiB5b3Vy
IGNvbW1hbmQuCj4gPgo+ID4gQWxleCBHdXR0ZXJpZGdlCj4gPgo+ID4gQmlvaW5mb3JtYXRpY3Mg
Q2VudGVyCj4gPiBLeW90byBVbml2ZXJzaXR5Cj4KPiBQbGVhc2UgdGVsbCBtZSBpZiBpIGhhdmUg
YSBzY3JpcHQgZmlsZSBzYXkgc2NyaXB0ZmlsZSwgdGhlbiBob3cgaSBjYW4KPiBydW4gdGhhdCBm
aWxlIHVzaW5nIHJ1YnkuCj4gUGxlYXNlIGV4cGxhYWluIHdpdGggZXhhbXBsZS4KCihhc3N1bWlu
ZyBVbml4aXNoIHN5c3RlbSkKYmFzaCQgY2F0ID4gdApwICJoZWxsbyB3b3JsZCEiCkN0cmwuZCAo
UHJlc3NpbmcgQ3RybCBhbmQgZCBrZXkpCgpiYXNoJCBydWJ5IC1lICdzeXN0ZW0oInJ1YnkiLCAi
dCIpJwpoZWxsbyB3b3JsZCEKYmFzaCQKCgo+IERoaXJhago+Cj4gLS0KPiBQb3N0ZWQgdmlhIGh0
dHA6Ly93d3cucnVieS1mb3J1bS5jb20vLgo+Cj4KCgotLSAK4KSF4KSt4KS/4KSc4KWA4KSkCgpb
IHdyaXR0ZW4gaW4gaHR0cDovL3d3dy5wYWFoaWplbi5jb20vc2NyYXRjaHBhZCBdCgpbIGh0dHA6
Ly93d3cucGFhaGlqZW4uY29tIF0K
 
A

Alex Gutteridge

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
 
D

Dhiraj Girdhar

Alex said:
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
 
B

Björn Paetzel

Dhiraj said:
#!/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?
 
A

Alex Gutteridge

Alex said:
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
 
A

Ari Brown

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
 
D

Dhiraj Girdhar

Ari said:
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
 
A

Ari Brown

On Apr 26, 2007, at 7:29 AM, Dhiraj Girdhar wrote:
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
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top