Page 1 of 1

openwith function and redirecting command line output with >

Posted: 17 Jun 2009 22:39
by bugger
I'm loving XY still, and trying to do some more automation but just ran into a stumbler that's probably simple. I want to use openwith to call a program. The program takes a filename as its second argument, then writes out a SHA256 hash. I want to redirect the programs output to a file using the '>' redirection.

Normally I run this program from the command line as:

c:\hasher sha256 filein > fileout

Where sha256 is the program's first argument telling it what type of hashing to do. I've been playing with openwith to the point of frustration so now I'm posting for help. I've tried stuff like:

::openwith """C:\hasher.exe"" sha256 ""<curitem>"" > ""<curitem>.sha256"""

::openwith "C:\hasher.exe" sha256 "<curitem>" > "<curitem>.sha256"

::openwith "C:\hasher.exe" sha256 "<curitem>" '>' "<curitem>.sha256"

Re: openwith function and redirecting command line output with >

Posted: 17 Jun 2009 22:50
by TheQwerty
I'd try using Run instead, simply because it should give you better control over how the arguments are passed (plus you can then have the script halt until hasher has finished).

I think this should work:

Code: Select all

Run("""C:\hasher.exe"" sha256 ""<curitem>"" > ""<curitem>.sha256""");

Re: openwith function and redirecting command line output with >

Posted: 18 Jun 2009 00:16
by bugger
Thanks, I ended up going with this:

Code: Select all

::Run("cmd /k ""hasher.exe"" sha256 <curitem> > <curitem>.sha256");
Not optimal because the cmd window stays open but I couldn't get the redirect working in the other case.

Re: openwith function and redirecting command line output with >

Posted: 18 Jun 2009 00:47
by Muroph
bugger wrote:

Code: Select all

::Run("cmd /k ""hasher.exe"" sha256 <curitem> > <curitem>.sha256");
Not optimal because the cmd window stays open but I couldn't get the redirect working in the other case.
use "/c" instead of "/k" :wink:

Re: openwith function and redirecting command line output with >

Posted: 18 Jun 2009 02:09
by TheQwerty
bugger wrote:I couldn't get the redirect working in the other case.
After I submitted that post I had a feeling that would be the case.

Really this is something I've asked Don to implement in script before, but I'd really like to see the Run/Open script commands converted to functions which return what might be printed to the console or the returned error level.

Then you'd have the computed hash and be able to use WriteFile or manipulate it further. (This would also be a solution for that person who requested a way to get SVN repository urls today.)