I'm running a Ruby script from TextMate and within that script call a Perl script (gpsPhoto.pl) and would like to capture the error messages and act on them. The messages show up in the TM Running window.
An example of an error that appears in the TM Running window:
Use of uninitialized value $text in pattern match (m//) at /someFolderOnMyMac/gpsPhoto.pl line 3120.
Thanks for any ideas.
Greg
On Thu, Jun 30, 2011 at 21:58, Greg web@web.knobby.ws wrote:
I'm running a Ruby script from TextMate and within that script call a Perl script (gpsPhoto.pl) and would like to capture the error messages and act on them. The messages show up in the TM Running window.
There's nothing TextMate-specific about this, you can capture those messages any way you would otherwise in Ruby. Which way that is depends on how you call the other command, e.g. with backticks you would append `2>&1` to the command line.
If you're unsure, [1] has a survey of ways to run subprocesses in Ruby.
HTH, Martin
[1] http://tech.natemurray.com/2007/03/ruby-shell-commands.html
On Jun 30, 2011, at 10:42 PM, Martin Kühl wrote:
On Thu, Jun 30, 2011 at 21:58, Greg web@web.knobby.ws wrote:
I'm running a Ruby script from TextMate and within that script call a Perl script (gpsPhoto.pl) and would like to capture the error messages and act on them. The messages show up in the TM Running window.
There's nothing TextMate-specific about this, you can capture those messages any way you would otherwise in Ruby. Which way that is depends on how you call the other command, e.g. with backticks you would append `2>&1` to the command line.
If you're unsure, [1] has a survey of ways to run subprocesses in Ruby.
HTH, Martin
[1] http://tech.natemurray.com/2007/03/ruby-shell-commands.html
Thank you. I think this will point me in the right direction. Greg
On Jun 30, 2011, at 10:42 PM, Martin Kühl wrote:
On Thu, Jun 30, 2011 at 21:58, Greg web@web.knobby.ws wrote:
I'm running a Ruby script from TextMate and within that script call a Perl script (gpsPhoto.pl) and would like to capture the error messages and act on them. The messages show up in the TM Running window.
There's nothing TextMate-specific about this, you can capture those messages any way you would otherwise in Ruby. Which way that is depends on how you call the other command, e.g. with backticks you would append `2>&1` to the command line.
If you're unsure, [1] has a survey of ways to run subprocesses in Ruby.
HTH, Martin
[1] http://tech.natemurray.com/2007/03/ruby-shell-commands.html
Neophyte that I am it took a little bit of thinking. Mainly was to just set the call to Perl like so:
perlOutput = `perl "#{gpsPhotoLoc}" --image "#{imageFile}" --gpsfile "#{gpxFile}" --timeoffset #{geoOffset} --maxtimediff #{maxTimeDiff} --maxdistance #{maxDistance} --geoinfo wikipedia --city auto --state guess --country guess`
I didn't have the perlOutput = before. $STDERR has info when the Perl script has an error and perlOutput gives info on what happens when the script runs. So found what I was looking for.
One question: would the `2>&1` comment still apply? It didn't make any difference when I added the 2>&1 to the end of backtick quoted line.
Learning slowly.
On Sat, Jul 2, 2011 at 23:14, Greg web@web.knobby.ws wrote:
On Jun 30, 2011, at 10:42 PM, Martin Kühl wrote:
On Thu, Jun 30, 2011 at 21:58, Greg web@web.knobby.ws wrote:
I'm running a Ruby script from TextMate and within that script call a Perl script (gpsPhoto.pl) and would like to capture the error messages and act on them. The messages show up in the TM Running window.
There's nothing TextMate-specific about this, you can capture those messages any way you would otherwise in Ruby. Which way that is depends on how you call the other command, e.g. with backticks you would append `2>&1` to the command line.
If you're unsure, [1] has a survey of ways to run subprocesses in Ruby.
HTH, Martin
[1] http://tech.natemurray.com/2007/03/ruby-shell-commands.html
Neophyte that I am it took a little bit of thinking. Mainly was to just set the call to Perl like so:
perlOutput = `perl "#{gpsPhotoLoc}" --image "#{imageFile}" --gpsfile "#{gpxFile}" --timeoffset #{geoOffset} --maxtimediff #{maxTimeDiff} --maxdistance #{maxDistance} --geoinfo wikipedia --city auto --state guess --country guess`
I didn't have the perlOutput = before. $STDERR has info when the Perl script has an error and perlOutput gives info on what happens when the script runs. So found what I was looking for.
One question: would the `2>&1` comment still apply? It didn't make any difference when I added the 2>&1 to the end of backtick quoted line.
Short answer: No, probably not.
Longer answer: Scripts have two "channels" for messages, one for output and one for error messages. After your command, `perlOutput` contains messages from the former. If you append `2>&1` to the command (inside the backticks) it will contain messages from either. If a script doesn't use the error channel it won't make any difference.
Learning slowly.
Isn't that the only way? :-)
Martin
On Jul 3, 2011, at 12:58 AM, Martin Kühl wrote:
Scripts have two "channels" for messages, one for output and one for error messages. After your command, `perlOutput` contains messages from the former. If you append `2>&1` to the command (inside the backticks) it will contain messages from either. If a script doesn't use the error channel it won't make any difference.
Glad I asked. Does make a difference. The script does return error info. I had taken it out thinking to not have stuff in the script that might cause problems and took it out before noticing the difference.