#137453 - 2005-04-07 07:58 PM
Put the resutls of a Shell command into a variable??
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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?
|
Top
|
|
|
|
#137455 - 2005-04-07 08:13 PM
Re: Put the resutls of a Shell command into a variable??
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
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"
|
Top
|
|
|
|
#137457 - 2005-04-07 11:03 PM
Re: Put the resutls of a Shell command into a variable??
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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?
|
Top
|
|
|
|
#137460 - 2005-04-07 11:25 PM
Re: Put the resutls of a Shell command into a variable??
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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...
|
Top
|
|
|
|
#137466 - 2005-04-08 05:33 PM
Re: Put the resutls of a Shell command into a variable??
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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...
Edited by thepip3r (2005-04-08 05:34 PM)
|
Top
|
|
|
|
#137468 - 2005-04-08 06:10 PM
Re: Put the resutls of a Shell command into a variable??
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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)
??
|
Top
|
|
|
|
#137469 - 2005-04-08 06:19 PM
Re: Put the resutls of a Shell command into a variable??
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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?
Edited by thepip3r (2005-04-08 06:20 PM)
|
Top
|
|
|
|
#137471 - 2005-04-08 06:29 PM
Re: Put the resutls of a Shell command into a variable??
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
I think you're missing a quote (') here... Code:
SHELL '%COMSPEC% /e:1024 /c "dir /b /ad /o-n %ProgramFiles%\Java\ >> c:\JavaDirectory.txt"
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|