Conditionnement de commandes DOS dans un script vbs ?
Bonjour,
Dans un script VBS qui, en gros, cherche un fichier pour y passer, en ligne de commande, une moulinette "AWStats" (Perl) qui génére un autre fichier qui sera utilisée pour updater un fichier de stats (une autre ligne de commande)...
Voici un extrait du script (qui fonctionne :D):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| ' Search and convert exchange log
If fso.FileExists(exchange_log_directory & filenametosearch) Then
' If file exists, run awstats convert tool : maillogconvert.pl'
Dim osShell,awstat_converted_log_directory,cmd_line_goto_directory, cmd_line_run_awstats_tool,fichier_conf_aws
awstat_converted_log_directory = "C:\Inetpub\wwwroot\AWStats\converted_mail_log\"
Set osShell = CreateObject("WScript.Shell")
cmd_line_goto_directory = "cmd /C CD C:\Inetpub\wwwroot\AWStats\tools"
cmd_line_run_awstats_tool = "& maillogconvert.pl standard " & exchange_log_directory & filenametosearch & " > " & awstat_converted_log_directory & filenametosearch
osShell.Run cmd_line_goto_directory & cmd_line_run_awstats_tool, 0, true
Set osShell = Nothing
f.WriteLine(Now() & " - Conversion de la log Exchange : " & exchange_log_directory & filenametosearch )
f.WriteLine(Now() & " - dans : " & awstat_converted_log_directory & filenametosearch)
' Search converted log and create awstats datas file
If fso.FileExists(awstat_converted_log_directory & filenametosearch) Then
' If file exists, run awstats tool : awstats.pl'
Set osShell = CreateObject("WScript.Shell")
fichier_conf_aws = "messagerie-exchange"
cmd_line_goto_directory = "cmd /C CD C:\Inetpub\wwwroot\AWStats\cgi-bin"
cmd_line_run_awstats_tool = "& awstats.pl -config=" & fichier_conf_aws & " -update"
osShell.Run cmd_line_goto_directory & cmd_line_run_awstats_tool, 0, true
Set osShell = Nothing
f.WriteLine(Now() & " - Mise a jour des stats AWSTats avec le fichier : " & fichier_conf_aws )
End If
Else
f.WriteLine(Now() & " - Pas de log Exchange trouvee : " & exchange_log_directory & filenametosearch )
End If |
mais, étant novice en VBS et après avoir consulté moult ressources (ici et ailleurs), j'aimerais savoir si cette façon de faire est correcte et si, d'après ce que j'ai compris, le paramètre "true" (osShell.Run xxxxxxxxxxxxx, 0, true ) suffit à ne lancer la seconde ligne de commande qu'à la fin de l'éxecution de la première ?
Si le programme lancé en ligne de commande se plante, comment récupérer un code erreur ?
D'autre part, à propos de la méthode "Run" la doc Win. dit ceci : -"The Run method returns an integer. " oui, mais qui correspond à quoi ? (temps d'éxec. en milisecondes ou ... ?)
Avec mes remerciements,
Cordialement,
Thierry