openwith function and redirecting command line output with >

Discuss and share scripts and script files...
Post Reply
bugger
Posts: 47
Joined: 07 Apr 2008 19:03

openwith function and redirecting command line output with >

Post 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"

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: openwith function and redirecting command line output with >

Post 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""");

bugger
Posts: 47
Joined: 07 Apr 2008 19:03

Re: openwith function and redirecting command line output with >

Post 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.

Muroph
Posts: 561
Joined: 21 Aug 2007 16:13

Re: openwith function and redirecting command line output with >

Post 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:
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: openwith function and redirecting command line output with >

Post 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.)

Post Reply