Rose Perrone
Rose Perrone

Reputation: 63616

Execute commands in a specific shell within Ruby?

I need to run some commands within a Ruby file, but rather than running them in Bash, because I'm on Unix, I want to run them in a different shell, called "s3sh". How can I specify the shell?

For example, in my Ruby code, I tried:

 system "export RUBYSHELL=s3sh"
 s3 = system "RightAws::S3Interface.new(#{S3ID}, #{S3KEY})"
 system "s3.copy(#{SRCBUCKET}, #{FILE}, #{DESTBUCKET}, #{FILE})"
 system "unset RUBYSHELL"

but it's not possible export environment variables to the shell the Ruby script runs in. (see "Exporting an Environment Variable in Ruby")

Upvotes: 0

Views: 203

Answers (1)

Darshan Rivka Whittle
Darshan Rivka Whittle

Reputation: 34061

s3sh is just a wrapper around the AWS::S3 gem, so you're over-complicating things. You don't need to shell out; you can just use Ruby:

require 'right_aws'

s3 = RightAws::S3Interface.new(S3ID, S3KEY)
s3.copy(SRCBUCKET, FILE, DESTBUCKET, FILE)

Upvotes: 2

Related Questions