Page 1 of 1 1
Topic Options
#46842 - 2003-10-16 11:04 AM Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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
_________________________
Jeff Lynch Network Administrator

Top
#46843 - 2003-10-16 11:12 AM Re: Retrieving error code from shell
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
$ExchsrvIS="MSExchangeIS"
Shell 'net start $ExchsrvIS'
"error returned: (" @error ") " @serror

is what you are looking for.
_________________________
!

download KiXnet

Top
#46844 - 2003-10-16 11:26 AM Re: Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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
_________________________
Jeff Lynch Network Administrator

Top
#46845 - 2003-10-16 11:31 AM Re: Retrieving error code from shell
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
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


Top
#46846 - 2003-10-16 11:34 AM Re: Retrieving error code from shell
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
Sorry forgot to say what Error check is producing error 2, @ERROR OR @SERROR.

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

Top
#46847 - 2003-10-16 11:37 AM Re: Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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.
_________________________
Jeff Lynch Network Administrator

Top
#46848 - 2003-10-17 12:14 AM Re: Retrieving error code from shell
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
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 ]

Top
#46849 - 2003-10-17 12:16 AM Re: Retrieving error code from shell
Lonkero Administrator Offline
KiX Master Guru
*****

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

download KiXnet

Top
#46850 - 2003-10-17 12:25 AM Re: Retrieving error code from shell
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
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]

Top
#46851 - 2003-10-17 12:29 AM Re: Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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?
_________________________
Jeff Lynch Network Administrator

Top
#46852 - 2003-10-17 12:34 AM Re: Retrieving error code from shell
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
Can you start and stop the service via a command line.

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

Top
#46853 - 2003-10-17 12:38 AM Re: Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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
_________________________
Jeff Lynch Network Administrator

Top
#46854 - 2003-10-17 12:43 AM Re: Retrieving error code from shell
Lonkero Administrator Offline
KiX Master Guru
*****

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

download KiXnet

Top
#46855 - 2003-10-16 02:11 PM Re: Retrieving error code from shell
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
It may have just been a transcription typo in your first post, but the command intepreter is %COMSPEC%, not %CompSpec%
Top
#46856 - 2003-10-16 09:43 PM Re: Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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?
_________________________
Jeff Lynch Network Administrator

Top
#46857 - 2003-10-16 09:56 PM Re: Retrieving error code from shell
Lonkero Administrator Offline
KiX Master Guru
*****

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

download KiXnet

Top
#46858 - 2003-10-16 10:31 PM Re: Retrieving error code from shell
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46859 - 2003-10-16 10:52 PM Re: Retrieving error code from shell
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#46860 - 2003-10-18 05:39 AM Re: Retrieving error code from shell
schnazzy Offline
Fresh Scripter

Registered: 2000-07-12
Posts: 23
Loc: New York, NY USA
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
_________________________
Jeff Lynch Network Administrator

Top
#46861 - 2003-10-18 02:48 PM Re: Retrieving error code from shell
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 146 anonymous users online.
Newest Members
nremmel, AlexTheGreat, ovdmtz, AlexPallaress, wschenk
17490 Registered Users

Generated in 0.083 seconds in which 0.027 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