Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue to get errors with a shell command

Status
Not open for further replies.

noche

Programmer
Jan 28, 2009
1
Hello,

my script must launch some schedule tasks on remote servers. It works if the command is well written and in general with the rights it's OK. But when the command is wrong, I don't have any notification about an error and i could believe the command was successful.
(by exemple, if I made an error on getting the password or if the path is wrong, nothing alerts me).

Here is the code :

Code:
Set fso = Wscript.createObject("Scripting.FileSystemObject") 
Set oShell = Wscript.createObject("Wscript.Shell") 
.... 
'Lancement du fichier 
Set oInput = fso.openTextFile(scriptPath & "input.txt",1,False) 
Do Until oInput.AtEndOfStream 
sRead = oInput.readline 
If left(sRead, 1) <> "'" Then 
   If InStr(sRead,";") > 0 And Left(sRead,1) <> "'" Then 
     array_Server = Split(sRead,";") 
     If UBOUND(array_Server) < 1 Then 
              Wscript.quit 
     End If 
     err.clear 
     genMinutes 
     strServer = array_Server(0) 
     DomainControl=DC(strServer) 
    'Wscript.echo DomainControl 
     sCmd="schtasks /create /tn Task /tr \\toto\truc.cmd /sc daily /st 05:11:00 /s "& strServer &" /u domain\login /p """& sPassword &"""" 
     wscript.echo sCmd 
     sCmd=sCmd & ">" & cfile 
     Wscript.echo sCmd 
     sReturn =oShell.Run(sCmd,0,True) 
     If err <> 0 Then 
   MsgBox ("Erreur N°" & CStr(Err.Number) & " " & err.Description) 
   echo err.Number & " " & err.Description 
   End if 
  End If 
End If 
Loop

I have tried to put cmd & > C:\toto.txt but I just get success, not errors. why?
Thanks by advance for any help or comment,
Noche
 
Try this.
>sCmd=sCmd & ">" & cfile
[tt]sCmd=sCmd & ">" & cfile & " 2>&1"[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top