Page 1 of 2 12>
Topic Options
#137453 - 2005-04-07 07:58 PM Put the resutls of a Shell command into a variable??
thepip3r Offline
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
#137454 - 2005-04-07 08:12 PM Re: Put the resutls of a Shell command into a variable??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if the output is put to console, try:
Code:

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

_________________________
!

download KiXnet

Top
#137455 - 2005-04-07 08:13 PM Re: Put the resutls of a Shell command into a variable??
Radimus Moderator Offline
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"
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137456 - 2005-04-07 09:17 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
thanx gentlemen
Top
#137457 - 2005-04-07 11:03 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
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
#137458 - 2005-04-07 11:07 PM Re: Put the resutls of a Shell command into a variable??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#137459 - 2005-04-07 11:11 PM Re: Put the resutls of a Shell command into a variable??
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Anything useful in this registry key ?

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion

-Shawn

Top
#137460 - 2005-04-07 11:25 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
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
#137461 - 2005-04-07 11:39 PM Re: Put the resutls of a Shell command into a variable??
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you right-click on the file and it does not show version, then neither KiX nor FSO would return it either.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137462 - 2005-04-07 11:50 PM Re: Put the resutls of a Shell command into a variable??
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137463 - 2005-04-08 01:20 AM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Thanx Les... I didn't think of that.
Top
#137464 - 2005-04-08 09:15 AM Re: Put the resutls of a Shell command into a variable??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well.
if you don't like blank screen, please output that bloody error:
Code:

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

_________________________
!

download KiXnet

Top
#137465 - 2005-04-08 05:30 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
So you're saying my error checking above wouldn't work?
Top
#137466 - 2005-04-08 05:33 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
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
#137467 - 2005-04-08 05:58 PM Re: Put the resutls of a Shell command into a variable??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes, I'm saying your code with the error checking actually disables the error checking.
loose all the crap and just take my example.
_________________________
!

download KiXnet

Top
#137468 - 2005-04-08 06:10 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
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 Offline
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
#137470 - 2005-04-08 06:26 PM Re: Put the resutls of a Shell command into a variable??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#137471 - 2005-04-08 06:29 PM Re: Put the resutls of a Shell command into a variable??
maciep Offline
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
#137472 - 2005-04-08 06:48 PM Re: Put the resutls of a Shell command into a variable??
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
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!


Edited by thepip3r (2005-04-08 06:49 PM)

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

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