I’d like to use gpsPhoto.pl in a Ruby script.
http://www.carto.net/projects/photoTools/gpsPhoto/
Assuming I have the script on my computer.
Syntax from command line is:
perl gpsPhoto.pl --dir photos/ --gpsfile GPSTrackWithTime.gpx
–timeoffset 10800
Can I include this in a Ruby script? Please don’t suggest porting it to
Ruby, it’s 400 lines,
Thanks
12 34 wrote:
perl gpsPhoto.pl --dir photos/ --gpsfile GPSTrackWithTime.gpx
–timeoffset 10800
Can I include this in a Ruby script? Please don’t suggest porting it to
Ruby, it’s 400 lines,
Check out the system() method.
Is there anything wrong with:
output_string = perl gpsPhoto.pl [blah, blah, ....]
?
The backticks ` are the part to note carefully.
“12 34” [email protected] wrote in message
news:[email protected]…
On Jul 14, 2007, at 9:44 PM, M. Edward (Ed) Borasky wrote:
application-dependent error number. If Ruby is returning “true” on
success and “false” on failure, that’s different from what many
environments do.
It does, but you can get the exit code:
system(“date”) # => true
$?.to_i # => 0
>> Sat Jul 14 23:11:49 CDT 2007
James Edward G. II
Dave C. wrote:
Tim H. wrote:
Check out the system() method.
looks like system only returns true or false if the system call executes
successfully. What if you want to evaluate what’s returned from that
perl script?
IIRC “system” returns the (implementation-dependent) numerical return
code of the call, where by tradition “0” is success and non-zero is an
application-dependent error number. If Ruby is returning “true” on
success and “false” on failure, that’s different from what many
environments do.
On Jul 14, 2007, at 9:12 PM, James Edward G. II wrote:
IIRC “system” returns the (implementation-dependent) numerical return
>> Sat Jul 14 23:11:49 CDT 2007
There is also Kernel.`` which will return stdout. If you’re looking
for something more powerful still look at popen, Open3, or (best of
all ;D) the Open4 gem.
Corey
Ron Mr. wrote:
Dave C. wrote:
Tim H. wrote:
Check out the system() method.
looks like system only returns true or false if the system call executes
successfully. What if you want to evaluate what’s returned from that
perl script?
backticks my friend
Thanks, backticks are my friend. The time delay in responding was due to
sorting out the Perl script–my issues a a minor bug in the script which
was quickly fixed.
I want to be able to use Ruby variables in the Perl script. Here’s the
command line script:
perl gpsPhoto.pl --dir photos/ --gpsfile GPSTrackWithTime.gpx
–timeoffset )
I can hard code the location of the gpsPhoto.pl, dir, etc, but I want to
use Ruby variables, e.g.
perl gpsPhotoLoc --dir destPhoto --gpsfile gpxFiles --timeoffset 0
where e.g.
“/Users/me/Library/Scripts/Digital Camera Scripts/gpsPhoto.w.pl”
Thanks for any suggestions
Original poster here.
Thanks to all. You’ve given me things to look at. And fortunately I
don’t have to interact with the script, nor do I need a response. There
is some information I’d like back, but I’m not sure without reading up
on it whether the script supplies the information.
Thanks again.
12 34 wrote:
Answering own question:
gpxFiles = gpxDateFN.join("" " ")
perl \"#{gpsPhotoLoc}\" --dir \"#{destPhoto}\" --gpsfile \"#{gpxFiles}\" --timeoffset #{timeOffset}
All the double quotes are needed because the file names have spaces in
them, and gpxFiles is a list of file names with a space in between each
item. Rather ugly solution.
class String
Transforms this string into an escaped POSIX shell argument.
def shell_escape
inspect.gsub(/\(\d{3})/) {$1.to_i(8).chr}
end
end
Open to suggestions on getting a string list
from an array with double quotes around each item and a space between
each item.
your_array.map {|s| s.shell_escape}.join(’ ')
Suraj K. wrote:
12 34 wrote:
class String
Transforms this string into an escaped POSIX shell argument.
def shell_escape
inspect.gsub(/\(\d{3})/) {$1.to_i(8).chr}
end
end
Open to suggestions on getting a string list
from an array with double quotes around each item and a space between
each item.
your_array.map {|s| s.shell_escape}.join(’ ')
Thank you. Much more Rubyesh.
Answering own question:
gpxFiles = gpxDateFN.join("" " ")
perl \"#{gpsPhotoLoc}\" --dir \"#{destPhoto}\" --gpsfile \"#{gpxFiles}\" --timeoffset #{timeOffset}
All the double quotes are needed because the file names have spaces in
them, and gpxFiles is a list of file names with a space in between each
item. Rather ugly solution. Open to suggestions on getting a string list
from an array with double quotes around each item and a space between
each item.
But it’s working I think. I need to exercise it some to make sure.
Ryan D. wrote:
http://vanity.zenspider.com.nyud.net:8090/~ryan/mov/perl2.mov
Wow, is this your Perl handler for RubyInline (which was mentioned by
Eric H. on this thread:
Use Perl modules from Ruby? - Ruby - Ruby-Forum)?
I’ve been waiting for months for any information on how to use Perl
modules from within Ruby (I’m trying to convince my employer to use Ruby
but they won’t consider it unless Ruby can leverage their existing Perl
modules for the time being).
Could you please tell us more about your Perl handler? I don’t see it
listed in the Zen Spider Software website.
Thanks for your consideration.
On Jul 22, 2007, at 23:16 , 12 34 wrote:
I want to be able to use Ruby variables in the Perl script. Here’s the
command line script:
perl gpsPhoto.pl --dir photos/ --gpsfile GPSTrackWithTime.gpx
–timeoffset )
or you could get really gross:
http://vanity.zenspider.com.nyud.net:8090/~ryan/mov/perl2.mov
(no, I don’t actually recommend this approach–it is just funny)
M. Edward (Ed) Borasky wrote:
Suraj K. wrote:
I’m trying to convince my employer to use Ruby but they won’t consider
it unless Ruby can leverage their existing Perl modules for the time being
You can always use RSpec to leverage Ruby into almost any situation.
RSpec is indeed a tasty treat. However, change is not driven by
external temptation alone; it also requires internal effort. In other
words, it is as the Buddha once said: “first intention, then
enlightenment”.