thepip3r
(Hey THIS is FUN)
2005-04-07 07:58 PM
Put the resutls of a Shell command into a variable??

I'm trying to get the contents of a command run from CMD to write to a file but an not sure how to accomplish this... Right now I have:

Code:
Break On

$computer = @WKSTA
? $computer + @CRLF
shell "%comspec% /c java -fullversion"
sleep 2



I've tried setting the "Shell" command to a var as below:

Code:
Break On

$computer = @WKSTA
? $computer + @CRLF
$x = shell "%comspec% /c java -fullversion"
sleep 2



so that I can write the information to a file but I get an error. Can anyone tell me how to go about this or even if I'm in the right mode of thinking?


LonkeroAdministrator
(KiX Master Guru)
2005-04-07 08:12 PM
Re: Put the resutls of a Shell command into a variable??

if the output is put to console, try:
Code:

shell "%comspec% /c java -fullversion > c:\temp\log.txt"



Radimus
(KiX Supporter)
2005-04-07 08:13 PM
Re: Put the resutls of a Shell command into a variable??

2 ways.. use the UDF WSHPipe() or pipe the results into a text file and then read the file

shell "%comspec% /c java -fullversion > c:\results.txt"


thepip3r
(Hey THIS is FUN)
2005-04-07 09:17 PM
Re: Put the resutls of a Shell command into a variable??

thanx gentlemen

thepip3r
(Hey THIS is FUN)
2005-04-07 11:03 PM
Re: Put the resutls of a Shell command into a variable??

Has anyone ever worked with Java before? I think it's jacked up...

I've tried many things but can't even get the file version to redirect into ANYTHING!!! Can someone please advise??

Here's what I've tried:

Code:
$result = GetFileVersion(%systemroot% + "\system32\java.exe")
?$result


Returns Nothing
Code:
shell %comspec% /c "java -fullversion >> c:\test.txt"


creates "test.txt" on the root of my C drive but no information in it.

Even just trying it from the command line yielded nothing. Does anyone know how to get the java.exe file version information from KiX?


LonkeroAdministrator
(KiX Master Guru)
2005-04-07 11:07 PM
Re: Put the resutls of a Shell command into a variable??

if getfileversion returns nothing, then you got a problem.
it shall return something. have you tried checking on the @error ?

I quess it's 2


ShawnAdministrator
(KiX Supporter)
2005-04-07 11:11 PM
Re: Put the resutls of a Shell command into a variable??

Anything useful in this registry key ?

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion

-Shawn


thepip3r
(Hey THIS is FUN)
2005-04-07 11:25 PM
Re: Put the resutls of a Shell command into a variable??

jokeli: Here is what I tried and it still returns nothing, just a blank screen:

Code:
Break On

If GetFileVersion(%systemroot% + "\system32\java.exe") = 0
$x = GetFileVersion(%systemroot% + "\system32\java.exe")
?$x
else
?"ERROR @ERROR : @SERROR"
Endif
sleep 2



Shawn: I'm currently looking into that.

Thank you both for the prompt suggestions...


Les
(KiX Master)
2005-04-07 11:39 PM
Re: Put the resutls of a Shell command into a variable??

If you right-click on the file and it does not show version, then neither KiX nor FSO would return it either.

Les
(KiX Master)
2005-04-07 11:50 PM
Re: Put the resutls of a Shell command into a variable??

Also, the topic says "Put the resutls of a Shell command into a variable" but java.exe is not a shell command. In fact, java.exe does not output to either STDOut or STDErr.

thepip3r
(Hey THIS is FUN)
2005-04-08 01:20 AM
Re: Put the resutls of a Shell command into a variable??

Thanx Les... I didn't think of that.

LonkeroAdministrator
(KiX Master Guru)
2005-04-08 09:15 AM
Re: Put the resutls of a Shell command into a variable??

well.
if you don't like blank screen, please output that bloody error:
Code:

GetFileVersion(%systemroot% + "\system32\java.exe") ?
@error ": " @SERROR
get $



thepip3r
(Hey THIS is FUN)
2005-04-08 05:30 PM
Re: Put the resutls of a Shell command into a variable??

So you're saying my error checking above wouldn't work?

thepip3r
(Hey THIS is FUN)
2005-04-08 05:33 PM
Re: Put the resutls of a Shell command into a variable??

Ok, so I've tried instead to grab the contents of the directory where Java gets installed to in order to find the newest version and I'm getting errors, is my error-trapping incorrect?

Code:
$LocalLogFolder = %SystemRoot% + '\GPOUpdates'
$JavaUpdates = '\\[server name]- Java Updates'
$LogFile = '\\[server name]- Java Updates\JavaUpdateResults.csv'
$Return=Chr(13)+Chr(10)
$date="@year@MonthNo@MDayNo"
$LogError = OPEN (5,$LogFile,5)
$LogText="@DATE,@TIME,@FULLNAME,@USERID,@COMMENT,@WKSTA,@IPADDRESS0,@ADDRESS,@LDOMAIN,@LSERVER,@PRODUCTTYPE,@BUILD,@CSD,@TICKS,"

SHELL '%COMSPEC% /e:1024 /c "dir /b /ad /o-n %ProgramFiles%\Java\ >> c:\JavaDirectory.txt"
if @error <> 0
? @error + ": " @serror
else
$ = OPEN (1, "c:\JavaDirectory.txt")
$BeforeJavaVersion = ReadLine(1)
$ = CLOSE (1)
ENDIF

$Version13 = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.3")
IF $Version13 = 1
$PatchedVersion = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.3.1_15")
IF $PatchedVersion = 0
RUN '$JavaUpdates\j2re-1_3_1_15-windows-i586.exe -s -a -s -f2$LocalLogFolder\JavaInstallV1.3.log'
ENDIF
ENDIF

$Version14 = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4")
IF $Version14 = 1
$PatchedVersion = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4.2_07")
IF $PatchedVersion = 0
RUN '$JavaUpdates\j2re-1_4_2_07-windows-i586-p.exe /s /v"/qn IEXPLORER=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L $LocalLogFolder\JavaInstallV1.4.log"'
? "Running update..."
ENDIF
ENDIF

$Version15 = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5")
IF $Version15 = 1
$PatchedVersion = KeyExist ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5.0_01")
IF $PatchedVersion = 0
RUN '$JavaUpdates\jre-1_5_0_01-windows-i586-p.exe /s /v"/qn IEXPLORER=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L $LocalLogFolder\JavaInstallV1.5.log"'
ENDIF
ENDIF

IF NOT $Version13 and NOT $Version14 and NOT $version15
RUN '$JavaUpdates\jre-1_5_0_01-windows-i586-p.exe /s /v"/qn IEXPLORER=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L $LocalLogFolder\JavaInstallV1.5.log"'
ENDIF

SHELL '%COMSPEC% /e:1024 /c "dir /b /ad /o-n %ProgramFiles%\Java\ >> c:\JavaDirectory.txt"
$ = OPEN (2, "c:\JavaDirectory.txt")
$AfterJavaVersion = ReadLine(2)
$ = CLOSE (2)

If $LogError=0
$ = WRITELINE(5,$LogText+$BeforeJavaVersion+","+$AfterJavaVersion+$Return)
EndIf
$ = CLOSE(5)

sleep 5

Exit



I keep getting error messages about line 22 [_3_1_15]. I tried to cut and paste the code into a different script and the $Version13 runs fine when it's by itself...


LonkeroAdministrator
(KiX Master Guru)
2005-04-08 05:58 PM
Re: Put the resutls of a Shell command into a variable??

yes, I'm saying your code with the error checking actually disables the error checking.
loose all the crap and just take my example.


thepip3r
(Hey THIS is FUN)
2005-04-08 06:10 PM
Re: Put the resutls of a Shell command into a variable??

like this then?

Code:
SHELL '%COMSPEC% /e:1024 /c dir /b /ad /o-n "%ProgramFiles%\Java\" >> c:\JavaDirectory.txt
? @error + ": " @serror
get $
$ = OPEN (1, "c:\JavaDirectory.txt")
$BeforeJavaVersion = ReadLine(1)
$ = CLOSE (1)



??


thepip3r
(Hey THIS is FUN)
2005-04-08 06:19 PM
Re: Put the resutls of a Shell command into a variable??

I modified it to try and see if i could locate the code where it's failing because now it runs and then disappears but doesn't do anything so I tried to add sleep commands in different portions of my code but none of them are executing either...

Code:
SHELL '%COMSPEC% /e:1024 /c dir /b /ad /o-n "%ProgramFiles%\Java\" > c:\JavaDirectory.txt
? @error + ": " @serror
get $
$ = OPEN (1, "c:\JavaDirectory.txt")
$BeforeJavaVersion = ReadLine(1)
$ = CLOSE (1)

? Step 1...
sleep 2

$Version13 = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.3")
IF $Version13
$PatchedVersion = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.3.1_15")
IF $PatchedVersion
RUN "$JavaUpdates\j2re-1_3_1_15-windows-i586.exe -s -a -s -f2$LocalLogFolder\JavaInstallV1.3.log"
? @error + ": " @serror
get $
ENDIF
ENDIF

? Step 2...
sleep 2

$Version14 = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4")
IF $Version14
$PatchedVersion = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4.2_07")
IF $PatchedVersion
RUN "$JavaUpdates\j2re-1_4_2_07-windows-i586-p.exe /s /v/qn IEXPLORER=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L $LocalLogFolder\JavaInstallV1.4.log"
? "Running update..."
ENDIF
ENDIF

? Step 3...
sleep 2

$Version15 = KEYEXIST ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5")
IF $Version15
$PatchedVersion = KeyExist ("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5.0_01")
IF $PatchedVersion
RUN "$JavaUpdates\jre-1_5_0_01-windows-i586-p.exe /s /v/qn IEXPLORER=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L $LocalLogFolder\JavaInstallV1.5.log"
ENDIF
ENDIF

? Step 4...
sleep 2



any suggestions?


LonkeroAdministrator
(KiX Master Guru)
2005-04-08 06:26 PM
Re: Put the resutls of a Shell command into a variable??

did you try running the lines I pasted?
simple getversion and error.
no iffing no other sh*t.
just pure and simple.
just like KISS teaches us.


maciep
(Korg Regular)
2005-04-08 06:29 PM
Re: Put the resutls of a Shell command into a variable??

I think you're missing a quote (') here...
Code:

SHELL '%COMSPEC% /e:1024 /c "dir /b /ad /o-n %ProgramFiles%\Java\ >> c:\JavaDirectory.txt"



thepip3r
(Hey THIS is FUN)
2005-04-08 06:48 PM
Re: Put the resutls of a Shell command into a variable??

jokeli: This is the error I get from your code:

1813: The specified resource type cannot be found in the image file.

so that's why i moved onto the new method...

maciep: When I remove that single quote though, it doesn't run at all and I don't know how to put error checking in there to where I could see what KiX is saying is wrong with the script!


Les
(KiX Master)
2005-04-08 06:57 PM
Re: Put the resutls of a Shell command into a variable??

Which is why I said "If you right-click on the file and it does not show version, then neither KiX nor FSO would return it either"

maciep
(Korg Regular)
2005-04-08 07:34 PM
Re: Put the resutls of a Shell command into a variable??

I didn't say you have too many quotes, i said you are missing one - more specifically the end quote.

SHELL '%COMSPEC% /e:1024 /c "dir /b /ad /o-n %ProgramFiles%\Java\ >> c:\JavaDirectory.txt"'

Probably won't solve your problem, but should be fixed anyway.