Page 1 of 1 1
Topic Options
#152042 - 2005-11-22 10:36 PM command result to a variable
Jorgeush Offline
Fresh Scripter

Registered: 2005-11-22
Posts: 11

Hi :
Is possible assign a command result to a variable with kixtart?
example:

$clamver=shell "c:\clam\clamscan.exe -V" ; Returns the antivirus version.

Please write the correct syntax.
TIA

Top
#152043 - 2005-11-22 11:17 PM Re: command result to a variable
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
look for WSHPipe in the UDF forum
or
shell "c:\clam\clamscan.exe -V >c:\temp.txt"
and read the temp file
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152044 - 2005-11-23 12:24 AM Re: command result to a variable
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I'm pretty sure that:
shell "c:\clam\clamscan.exe -V >c:\temp.txt"
would not work. There is a FAQ that explains why not.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152045 - 2005-11-23 03:40 AM Re: command result to a variable
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Yes.

From docs: SHELL sets the value of @ERROR to the exit code of the program that is run.

Try the following.

Code:
;dir of an existing directory
shell "%comspec% /c dir c:\data >nul"
?
? "result=" + @error
? @serror

;dir of an NON-existing directory
shell "%comspec% /c dir c:\dataZZ > nul"
?
? "result=" + @error
? @serror



[edit]

Apparently I did not properly read the desired results. WSHPIPE would be the best solution. then parse the result.

[/edit]


Edited by Howard Bullock (2005-11-23 03:43 AM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#152046 - 2005-11-23 10:07 AM Re: command result to a variable
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

I'm pretty sure that:
shell "c:\clam\clamscan.exe -V >c:\temp.txt"
would not work. There is a FAQ that explains why not.




Quite right.

In summary redirection (>), piping (|) and conditional execution (&&) are specifically features of the DOS interpreter/processor (CMD or COMMAND) not of the Windows execution environment.

This means that if you want to use these features you must execute them as parameters for CMD.

However if WSH is an option then as the guys have already said your best option is the wshPipe() UDF.

Top
#152047 - 2005-11-23 12:43 PM Re: command result to a variable
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ok then

shell "cmd /c c:\clam\clamscan.exe -V >c:\temp.txt"
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152048 - 2005-11-23 02:36 PM Re: command result to a variable
Jorgeush Offline
Fresh Scripter

Registered: 2005-11-22
Posts: 11
Oka thanks guys...
Top
#152049 - 2005-11-23 08:01 PM Re: command result to a variable
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Hmm, Rad must be having a tough morning..
Shell 'cmd /c . . .' is considered bad form - you should use %COMSPEC% instead of "cmd". Effectively, it's the same thing, but your script will be more portable if an environment uses a newer or specialized command interpreter.

Code:
Shell %ComSpec% + ' /c mycommand.exe args > log.txt'



Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#152050 - 2005-11-23 09:57 PM Re: command result to a variable
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Tch! %COMSPEC% is a fully qualified path, so may contain spaces. Always use adequate protection:
Code:
Shell '"'+%ComSpec% + '" /c mycommand.exe args > log.txt'


Top
#152051 - 2005-11-24 12:48 AM Re: command result to a variable
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Hittin' the eggnog a bit early myself!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#152052 - 2005-11-24 01:37 AM Re: command result to a variable
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
cmd is good enough for me... If I have a prob with comspec, then it is my fault
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


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

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

Generated in 0.06 seconds in which 0.024 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