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-forum.com/.
If that is really what you ran then you have a space in your command.
Alex Gutteridge
Bioinformatics Center
Kyoto University
···
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?
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
···
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
On Behalf Of Dhiraj Girdhar:
# abc = system(". /export/home/dhiraj/scriptfile.sh")
# puts abc
# The value of abc is false.
irb(main):001:0> system "cat ./test1"
echo hello
=> true
irb(main):002:0> system "./test1"
=> false
irb(main):003:0> system ". ./test1"
=> false
irb(main):004:0> system "bash . ./test1"
.: .: is a directory
=> false
irb(main):005:0> system "bash '. ./test1'"
bash: . ./test1: No such file or directory
=> false
irb(main):006:0> system "bash -c '. ./test1'"
hello
=> true
irb(main):007:0> system "bash -c '. ./testx'"
bash: ./testx: No such file or directory
=> false
irb(main):008:0>
irb(main):009:0* system "bash ./test1"
hello
=> true
irb(main):011:0> system "ls test*"
test1 test2.rb test.rb test.txt
=> true
# Please tell me why script file is not running?
you'll have to test it, i'm not sure if system() spawns a shell;
but we'll have to confirm from Nobu 
kind regards -botp
Ari Brown 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
···
On Apr 26, 2007, at 2:04 AM, Dhiraj Girdhar wrote:
--
Posted via http://www.ruby-forum.com/\.
Hi,
Please see below.
Alex Gutteridge 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 > t
p "hello world!"
Ctrl.d (Pressing Ctrl and d key)
bash$ ruby -e 'system("ruby", "t")'
hello world!
bash$
···
On 4/26/07, Dhiraj Girdhar <dgirdhar@arcot.com> wrote:
> On 26 Apr 2007, at 15:04, Dhiraj Girdhar wrote:
Dhiraj
--
Posted via http://www.ruby-forum.com/\.
--
अभिजीत
[ written in http://www.paahijen.com/scratchpad ]
[ http://www.paahijen.com ]
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
···
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.
<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
···
On Apr 26, 2007, at 7:29 AM, Dhiraj Girdhar wrote:
Alex Gutteridge 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
···
On 26 Apr 2007, at 15:33, Dhiraj Girdhar wrote:
--
Posted via http://www.ruby-forum.com/\.
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
···
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