Windows: "echo" vs "open process"

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Windows: "echo" vs "open process"

Post by ale870 » Thu Jan 28, 2010 12:01 pm

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!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

Timpraetor
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9
Joined: Thu Feb 04, 2010 7:12 pm

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

Post by Timpraetor » Fri Feb 12, 2010 1:10 am

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

Tim Jones
President / CTO
TOLIS Group, Inc.
http://www.tolisgroup.com
http://ww2.productionbackup.com

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

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

Post by ale870 » Fri Feb 12, 2010 9:02 am

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!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”