#66523 - 2002-06-10 02:20 PM
Pass the outcome of an .exe on to a variable within kix
|
Jeroen
Starting to like KiXtart
Registered: 2001-08-16
Posts: 180
Loc: Netherlands
|
Hi all,
I'd like to be able to pass the outcome of an .exe program on to a variable within kix. Kinda like:
Test.exe returns 'test1234'. How do I get test1234 in a variable $var without using tempfiles and readline etc ? By the way, the output generated by the program has 2 lines...
Anyone?
_________________________
Regards, Jeroen.
There are two ways to write error-free programs. Only the third one works.
|
|
Top
|
|
|
|
#66524 - 2002-06-10 02:28 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I don't think you can at this point. If someone else knows how then I would be interested to know as well.
|
|
Top
|
|
|
|
#66525 - 2002-06-10 02:45 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Did you write this exe yourself (or know who did) - the only other way to get the information back into your script (not using tempfiles) is to pass it through the registry, or through COM
|
|
Top
|
|
|
|
#66526 - 2002-06-10 02:50 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, to be truely not using a file (AKA Registry) it would have to be a COM object reference. (splitting hairs here.)
|
|
Top
|
|
|
|
#66529 - 2002-06-10 03:08 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I wish that KixTart permitted the redirection of STDOUT into the program using a pipe like Perl does. Hey a new item for the wishlist. code:
SRV:foreach $server (@Servers) { chomp($server); open (pingname, "ping $server|")
|
|
Top
|
|
|
|
#66530 - 2002-06-10 03:09 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Let's try this again. This script calls "ping.exe" and directs its output using "|" throught the FileHandle "pingname".
SRV: foreach $server (@Servers) { chomp($server); open (pingname, "ping $server|") || die "Can not ping"; while ($line = <pingname>) { chomp($line); print "$line"; if ($line =~ /Reply\s/) { print OUTFILE "$server\tActive\n"; print " - Active\n"; next SRV; } if ($line =~ /Bad IP\s/) { print " - Bad IP\n"; print OUTFILE "$server\tBad IP\n"; next SRV; } if ($line =~ /Request timed out/) { print " - Bad IP\n"; print OUTFILE "$server\tBad IP\n"; next SRV; } } }
Close SERVER; Close OUTPUT; [ 10 June 2002, 15:16: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#66532 - 2002-06-10 03:22 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
You can pass a variable by setting a global variable (such as in the autoexec.bat when you type SET PATH=...). Also, if you are having your program call kixtart itself, you can pass variables like:
KIX32 script.kix $a=info1 $b=info2
If the values are numeric or can be referenced by assigning unique numbers, you can set the errorlevel on exit and kix can read that.
At the current time you can't pipe to kix, although this has been a request for Ruud in the suggestion box.
I suppose if you were really resourceful, you could create a ramdrive and save a file there and read from it in kix before destroying the ram drive.
.... Just a few thoughts.
Brian
|
|
Top
|
|
|
|
#66534 - 2002-06-11 09:02 AM
Re: Pass the outcome of an .exe on to a variable within kix
|
Jeroen
Starting to like KiXtart
Registered: 2001-08-16
Posts: 180
Loc: Netherlands
|
Hi guys,
Thanks for the replies so far!
Where I'm going is this:
ZDU /, /i >tempfile.txt
(ZDU being a tool which tells us among other things the total disk size and the free disk space)
It's output is:
1234:13D1 - FS:NTFS - Cluster: 4k Total: 2,080,931,840 [1984M] - Free: 1,585,020,928 [1511M]
I'd like to skip the tempfile, and directly pass the output on to a variable so that I can pull the total disk space and the free space out of it.
I think skipping the tempfile will speed up the process, prevent defragmentation, & save code in the script, especially if you consider using this tool to check the space on multiple servers and drives, and for a longer period of time, to create an excel sheet which displays fluctuations over this period.
But, if passing it directly to a variable can't be done right now, we'll just use the old way, works fine, just requires a litte more open and close commands etc.
_________________________
Regards, Jeroen.
There are two ways to write error-free programs. Only the third one works.
|
|
Top
|
|
|
|
#66535 - 2002-06-11 03:16 PM
Re: Pass the outcome of an .exe on to a variable within kix
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Sure you can get the output without creating temporary files.
I've just posted a UDF here.
Ok, so I cheated a bit and used an external wrapper program, but it was an interesting exercise
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1376 anonymous users online.
|
|
|