Page 1 of 1 1
Topic Options
#66523 - 2002-06-10 02:20 PM Pass the outcome of an .exe on to a variable within kix
Jeroen Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66525 - 2002-06-10 02:45 PM Re: Pass the outcome of an .exe on to a variable within kix
Shawn Administrator Offline
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 [Wink]
Top
#66526 - 2002-06-10 02:50 PM Re: Pass the outcome of an .exe on to a variable within kix
Howard Bullock Offline
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.)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66527 - 2002-06-10 02:55 PM Re: Pass the outcome of an .exe on to a variable within kix
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, I was just wondering if there was a special reason why Jeron didn't want to use a tempfile (speed,security,whatever) ... and using COM would be a heck of a lot more complicated than tempfiles to be sure ...

Whats your reason Jeroen ? Were you just wondering if there was a cleaner way ?

-Shawn

[ 10 June 2002, 14:56: Message edited by: Shawn ]

Top
#66528 - 2002-06-10 03:01 PM Re: Pass the outcome of an .exe on to a variable within kix
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just kinda off-topic - wonder if there is a way to pipe the output of a commandline to one of the RESKIT REG tools, and have it go directly into the registry, kinda like this:

ipconfig /all | reg.exe HKCU\Software\MyKey\MyValue

If it did work, would there be any value (pun intended).

Top
#66529 - 2002-06-10 03:08 PM Re: Pass the outcome of an .exe on to a variable within kix
Howard Bullock Offline
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|")
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66530 - 2002-06-10 03:09 PM Re: Pass the outcome of an .exe on to a variable within kix
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66531 - 2002-06-10 03:17 PM Re: Pass the outcome of an .exe on to a variable within kix
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Howard,
Shawn and I (and a bunch of others) danced this topic a while back. From it was conceived Shawn's Pipe() UDF. A direct pipe would be nicer.

Shawn,
Piping directly into the reg doesn't sit well with me. Maybe to clipboard...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#66532 - 2002-06-10 03:22 PM Re: Pass the outcome of an .exe on to a variable within kix
BrianTX Offline
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
#66533 - 2002-06-10 03:49 PM Re: Pass the outcome of an .exe on to a variable within kix
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think Shawn's Pipe() UDF is the way to go in the absence of a 'direct' pipe.

BTW, here's the thread.

Topic: A coding challenge for you (well for me anyway)

Topic: Pipe - Submits a shell command and redirects output to an array

Topic: Pipe(2) - Submits a shell command and redirects output to an array
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#66534 - 2002-06-11 09:02 AM Re: Pass the outcome of an .exe on to a variable within kix
Jeroen Offline
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 Offline
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 [Big Grin]

Top
#66536 - 2002-06-11 03:52 PM Re: Pass the outcome of an .exe on to a variable within kix
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Jeroen:

If 'total disk size' and 'free disk space' is what you are looking for, then you should seriously investigate WMI (see the COM forum for posts). This would allow you to write a pure Kixtart solution without the need for any external program. WMI would even allow you to generate a complete hardware inventory in KiXtart.

There have been a couple of 'hardware inventory' scripts posted, just search for them, you'll find a pletora.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 476 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.065 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org