schnazzy
(Fresh Scripter)
2003-10-16 11:04 AM
Retrieving error code from shell

I am in the procces of completing a script that will allow for an Exchange 5.5 site swap and i am stuck at this point....
I need to get the results of the following command

$ExchsrvIS="MSExchangeIS"
Shell '%CompSpec% /c net start $ExchsrvIS'

Basically i have tried the @error and @serror, and both supply no usfull information. I need the errors generated from the service start request.
Errors i am expecting to see may be 5882, 1011, 1276, and normal ones like service started or service not started....
any advise would be most appreciated.
Environment is NT Server 4.0 SP6 with IE 4.0

Thanks in advance,
Jeff


LonkeroAdministrator
(KiX Master Guru)
2003-10-16 11:12 AM
Re: Retrieving error code from shell

$ExchsrvIS="MSExchangeIS"
Shell 'net start $ExchsrvIS'
"error returned: (" @error ") " @serror

is what you are looking for.


schnazzy
(Fresh Scripter)
2003-10-16 11:26 AM
Re: Retrieving error code from shell

thanks for the prompt reply,
error returned is 2 the system cannot find the file specified....
The actual error generated from the net start is...
The Microsoft Exchange Information Store could not be started.
A service specific error occurred:1276.

not sure how to get this msg to kix


Richie19Rich77
(Seasoned Scripter)
2003-10-16 11:31 AM
Re: Retrieving error code from shell

Well now you know that error 2 means "The Microsoft Exchange Information Store could not be started.
A service specific error occurred:1276."

so.
code:
$ExchsrvIS="MSExchangeIS"
Shell 'net start $ExchsrvIS'
If @ERROR = "2" ? "The Microsoft Exchange Information Store could not be started.
A service specific error occurred:1276." Endif



Richie19Rich77
(Seasoned Scripter)
2003-10-16 11:34 AM
Re: Retrieving error code from shell

Sorry forgot to say what Error check is producing error 2, @ERROR OR @SERROR.

Change If @ERROR = "2" depending on the error check.


schnazzy
(Fresh Scripter)
2003-10-16 11:37 AM
Re: Retrieving error code from shell

one problem with that is this,
if i issue a net stop command i get the same error code.
Scenero: MSExchange IS not started
net start gives error code 2, actual is ...
The Microsoft Exchange Information Store could not be started.
A service specific error occurred:1276
net stop gives error code 2, actual is ...
The Microsoft Exchange Information Store service is not started.


Richie19Rich77
(Seasoned Scripter)
2003-10-17 12:14 AM
Re: Retrieving error code from shell

This should work for you. $service = service name, $Option = 1 for start 0 for stop.

SERVICE("Print Spooler","0")

Get$

Function SERVICE($service, $Option)
If NOT $Option ? 'No Service Type Set' EndIf
Dim $objServer,$objService
$servername='.'
$ServerString = 'WinNT://' + $ServerName + ',computer'
$objServer = GetObject($ServerString)
$ServiceName = $service
$objService = $objServer.GetObject('Service', $ServiceName)

If $Option = 1
; - start the service
$objService.Start
If @ERROR = 0 ? 'Service "$ServiceName" started sucessfully"' Else ? 'Service "$ServiceName" is already running"'EndIf
Else
; - stop/start the service
$objService.Stop
If @ERROR = 0 ? 'Service "$ServiceName" stopped sucessfully"' Else ? 'Service "$ServiceName" is not running"'EndIf
EndIf
EndFunction


[ 16. October 2003, 12:16: Message edited by: Richard Farthing ]


LonkeroAdministrator
(KiX Master Guru)
2003-10-17 12:16 AM
Re: Retrieving error code from shell

heh.
boys boys.
the errors are STANDARD errorcodes.
you can't just change the meaning.
2 means what 2 means.
if it says 2, it has problem with net.
now, if it can't start net, I have to ask is your PATH variable screwed on that machine you try to fire it on.


Richie19Rich77
(Seasoned Scripter)
2003-10-17 12:25 AM
Re: Retrieving error code from shell

Woops Lonk is right, I should really read the questions before jumping in.

quote:
The Microsoft Exchange Information Store could not be started.
A service specific error occurred:1276

[Roll Eyes]


schnazzy
(Fresh Scripter)
2003-10-17 12:29 AM
Re: Retrieving error code from shell

okies, i be a tad confused...
if paths are messed up then how come the command does get executed and i get the service specifiv error code?


Richie19Rich77
(Seasoned Scripter)
2003-10-17 12:34 AM
Re: Retrieving error code from shell

Can you start and stop the service via a command line.

Does it Start and stop there without any error's.


schnazzy
(Fresh Scripter)
2003-10-17 12:38 AM
Re: Retrieving error code from shell

sure i can start the service from a command line with a clean DB in the exchange db directory.. will run a few more test on my way home, but most odd, not sure why it would be passing error code 2

LonkeroAdministrator
(KiX Master Guru)
2003-10-17 12:43 AM
Re: Retrieving error code from shell

not just on commandline but in the dir where the kix is and where the script is.
net.exe resides in system32.
so if %windir%\system32 is not on your %path%, the error 2 is obvious.
otherwise I have to wonder, wonder a lot.


Richard H.Administrator
(KiX Supporter)
2003-10-16 02:11 PM
Re: Retrieving error code from shell

It may have just been a transcription typo in your first post, but the command intepreter is %COMSPEC%, not %CompSpec%

schnazzy
(Fresh Scripter)
2003-10-16 09:43 PM
Re: Retrieving error code from shell

Okies, now I have made things very simple. And yes my path statement is correct, I thoroughly tested various net commands and all worked from every directory. The script has been changed to test against the alerter service which all NT/XP builds have out of the box.
Shell '%ComSpec% /c net stop alerter'
"error returned: (" @error ") " @serror

Scenario:
Alerter service stopped.

C:\Documents and Settings\lynchj>kix32 d:\kix\svcr1
The Alerter service is stopping.
The Alerter service was stopped successfully.

error returned: (0) The operation completed successfully.
C:\Documents and Settings\lynchj>kix32 d:\kix\svcr1
The Alerter service is not started.

More help is available by typing NET HELPMSG 3521.

error returned: (2) The system cannot find the file specified.
OK now I modified the net stop to be a net start and here are the results.

C:\Documents and Settings\lynchj>kix32 d:\kix\svcr1
The Alerter service is starting.
The Alerter service was started successfully.

error returned: (0) The operation completed successfully.
C:\Documents and Settings\lynchj>kix32 d:\kix\svcr1
The requested service has already been started.

More help is available by typing NET HELPMSG 2182.

error returned: (2) The system cannot find the file specified.

Okies, goal is to get the actual error txt that is displayed when attempting to start or stop the service, since it returns the same error code when starting or stopping the service. Haven't been stumped with a kix script in a while, and this doesn't logically seem all that hard which is what's making it all the more frustrating
Might i be barking up the wrong tree, is there an alternative that can be used to extract the error text?


LonkeroAdministrator
(KiX Master Guru)
2003-10-16 09:56 PM
Re: Retrieving error code from shell

k, me tested this stuff as don't wanted to say anything not true.
and found out that I already did.
net seems to NOT have standard errors even thought it should indeed be the standard for that same thing (net helpmsg)

it seems that it always returns 2 as error if service is already in the state you want to set it.
this is not in kix only but if you do:
net start workstation
echo %errorlevel%


on commandline, you see that it also returns same errors.


Howard Bullock
(KiX Supporter)
2003-10-16 10:31 PM
Re: Retrieving error code from shell

Please checkout my UDF as I believe that the set proper errorcode is set.

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000205

Don't quite know why you want to use 'SHELL "net ..."' anyway.

[ 16. October 2003, 22:31: Message edited by: Howard Bullock ]


Sealeopard
(KiX Master)
2003-10-16 10:52 PM
Re: Retrieving error code from shell

code:
$ExchsrvIS="MSExchangeIS"
Shell '%CompSpec% /c net start '+$ExchsrvIS+' >%TEMP%\status.log 2>%TEMP%\err.log'

will pipe the resulting messages into text files which can then be read via OPEN-READLINE-CLOSE. Alternativewly, use any of the 'pipe' UDFs.


schnazzy
(Fresh Scripter)
2003-10-18 05:39 AM
Re: Retrieving error code from shell

Thanks for all the assistance folks. This is as far as I have gotten, using excerpts from postings. Was wondering if this was clean or if it could be streamlined more.

Dim $ErrReturn[8]
$ExchsrvIS="MSExchangeIS"
Shell '%Comspec% /c net stop $ExchsrvIS >%Temp%\status.log 2>%Temp%\err.log'
$f=Open(1,"%Temp%\err.log",2)
$x=Readline(1)
While @error=0
$ErrReturn[$c]=$x
$x=Readline(1)
$c=$c+1
Loop
$f=Close(1)
$rc=Substr($ErrReturn[2],Len($ErrReturn[2])-4,4)
If $rc=""
$rc1=$ErrReturn[0]
$rc=Substr($ErrReturn[3],Len($ErrReturn[3])-4,4)
Endif
Select
Case $rc="2182" $ErrCode="The Requested service has already been started."
Case $rc="3521" $ErrCode="The "+$ExchsrvIS+" service is not started."
Case $rc="5882" $ErrCode="The RIP Key needs to be deleted and ExchangeSA needs to be restarted first." $RC1?
Case $rc="1011" $ErrCode="Isinteg needs to e run to bring PRIV to Consistant State." $RC1?
Case $rc="1276" $ErrCode="Restored PRIV not meant for current Site, Site needs to be swapped" $RC1?
EndSelect
?$ErrCode

Any feedback would be appreciated


Sealeopard
(KiX Master)
2003-10-18 02:48 PM
Re: Retrieving error code from shell

See the OPEN() example in the KiXtart Manual and use FREEFILEHANDLE() to assign a free filehandle instead of hardcoding it. You also do not check whether the OPEN() is successful. And see the UDF Forum for 'read file' and 'pipe' UDFs.