Page 1 of 1

Windows: "echo" vs "open process"

Posted: Thu Jan 28, 2010 12:01 pm
by ale870
Hello,
I need to send some data to SSL command (openssl.exe) used to calculate SHA1 code of a small string.
Well, if I use:

Code: Select all

echo MyStringToCheck|openssl sha1
it works perfectly (but my problem is "echo" command introduce an extra CR at the end of the string). So I wanted to send the string usin open process, but it seems it does not work in my case.
In fact when I use the following code:

Code: Select all

local p

set the hideConsoleWindows to false

put "openssl.exe " into p
open process p for text update

write "sha1 myPassword" & linefeed  to process p
read from process p until linefeed in 3 seconds
answer it

close process p

kill process p
I obtain:

mypassword: no such file or directory.

It seems openssl read myPassword as a file name (if you use openssl from command line, you need to supply a filename. For example: openssl.exe sha1 c:\myfilename.txt).

My problem is OPEN PROCESS seems to work differently from standard pipes and ECHO command: echo ..... | ......

Can you help me or give me some hints to solve this problem?

Thank you!

Re: Windows: "echo" vs "open process"

Posted: Fri Feb 12, 2010 1:10 am
by Timpraetor
What happens if you put the entire command into p just as if you were typing from the command line:

Code: Select all

put "echo MyStringToCheck | openssl sha1" into p
open process p for text update
...
I'm busy trying to get a handle on the various "process" member functions as well.

Re: Windows: "echo" vs "open process"

Posted: Fri Feb 12, 2010 9:02 am
by ale870
yes, in fact I solved in that way.
The problem is "echo" command in windows automatically add a NEWLINE (return) at the end of the string, and that char is calculated in SHA-1 :-(
So I solved using a linux version of the command (an equivalent command in windows was compiled), since that command has the option "-n" to eliminate newline char. In windows I found the command, which is called "ech.exe".

So....

Code: Select all

ech -n mystring|openssl sha1
                   ^^^
                     NO SPACE!!
Don't forget to eliminate the space between "mystring" and pipe "|" or that char will be included in sha-1 calculation.

Cheers!