Page 1 sur 1

récuperer la sorti d'un shell

MessagePublié: 21 Juin 2012 à 14:06
par Michael DELIQUE
Hello

en LS j’exécute une commande via un shell, ça affiche une console avec le résultat de dans, mais j'ai besoin de récupérer le résultat.

soit directement soit par l'intermédairie d'un fichier.

je trouve pas comment faire

mon code en ce moment

Code : Tout sélectionner
Commande = {ma commande > c:\temp\file222.txt}
Set vrShell = CreateObject("WScript.Shell")
   Call vrShell.Run(Commande,3,true)
   Set vrShell = Nothing


ça affiche bien le résultat mais impossible de le passer dans un fichier

Re: récuperer la sorti d'un shell

MessagePublié: 21 Juin 2012 à 14:54
par Michael DELIQUE
bon la seule solution trouvé, est de créé a la volé un point bat avec la command dedans

puis de lancer le bat via le sheel avec une redirection de sorti vers un fichier texte

Re: récuperer la sorti d'un shell

MessagePublié: 23 Juin 2012 à 09:05
par Michael DELIQUE
une autre solution plus sympa

passé par la variable "comspec"

Commande = {ma commande > c:\temp\file222.txt}
Set vrShell = CreateObject("WScript.Shell")
Call vrShell.Run({%comspec% /c "}+Commande+{"},3,true)
Set vrShell = Nothing

le souci c'est que si la commande contient des des doubles quotte ça bug !

Re: récuperer la sorti d'un shell

MessagePublié: 25 Juin 2012 à 10:31
par Michael DELIQUE
une autre solution qui ne marche pas a tous les coups

Code : Tout sélectionner
Public Function ShellPrint(wCommand As String, wFileToPrint As String)
   %REM
Description: permet de renvoyer une Command dos dans un fichier via un Shell
   attention ne fonctionne pas forcement s'il ya des double quotte dans la commande
   /C cmd no visible
   /k cmd visible
   %END REM
   
   Dim vrShell As Variant
   
   On Error GoTo CatchError

   If Trim(wCommand) = "" Then
      Error 9999,"wCommand is Empty"
   End If

   If Trim(wFileToPrint) = "" Then
      Error 9999,"wFileToPrint is Empty"
   End If

   Set vrShell = CreateObject("WScript.Shell")
   Call vrShell.Run({cmd = %comspec% /c "}+Trim(wCommand)+{" > }+Trim(wFileToPrint),0,True)
   Set vrShell = Nothing

   Exit Function
CatchError:
   MsgBox "("+Cstr(GetThreadInfo (1))+" Call by "+Cstr(GetThreadInfo(10))+")"+Chr(10)+"Error " + CStr(Err) + " : "+Chr(10) + CStr(Error)+". "+Chr(10)+"Line # "+Cstr(Erl),16," ERROR !"
   Exit Function
End Function

Re: récuperer la sorti d'un shell

MessagePublié: 29 Juin 2012 à 11:11
par Michael DELIQUE
bon j'avance pas, ma command est trop longue et bug le command.com (merci windows).
meme en réduisant au maximum je n'arrive pas a récupérer le résultat.

je suis passé par des api et (shellexecute) mais impossible de générer un fichier de retour ou de récupérer le résultat... si quelu'un a une idée je suis preneur