IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

[Process] - Récupérer la sortie


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de Anto03
    Inscrit en
    Octobre 2005
    Messages
    155
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 155
    Par défaut [Process] - Récupérer la sortie
    Bonjour,

    Je cherche à récupérer la sortie d'un processus voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
                    ProcessStartInfo process = new ProcessStartInfo();
                    process.RedirectStandardOutput = true;
                    process.CreateNoWindow = true;
                    process.UseShellExecute = false;
                    process.FileName = @"flv.exe";
                    process.Arguments = args;
                    p = Process.Start(process);
                    string s = p.StandardOutput.ReadToEnd();  
                    //p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
                    //p.BeginOutputReadLine();
                    p.WaitForExit();
    mais ma string s me renvoie une chaîne vide !! Alors que si j'exécute mon programme en mode console il affiche pleeeiin de ligne !! Quelqu'un peut il m'aider ? merci d'avance !

  2. #2
    Expert confirmé
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Par défaut
    Tu es parti à l'envers je crois bien.

    Regarde sur cette page en bas y'a un exemple de code
    http://msdn.microsoft.com/en-us/libr...ardoutput.aspx

  3. #3
    Membre confirmé Avatar de Anto03
    Inscrit en
    Octobre 2005
    Messages
    155
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 155
    Par défaut
    Merci pour ton aide et pour le lien !

    J'ai donc fait ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
                    Process myProcess = new Process();
                    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("flv.exe");
                    myProcessStartInfo.Arguments = GetParameters();
                    myProcessStartInfo.UseShellExecute = false;
                    myProcessStartInfo.RedirectStandardOutput = true;
                    myProcess.StartInfo = myProcessStartInfo;
                    myProcess.Start();
     
                    StreamReader myStreamReader = myProcess.StandardOutput;
                    string myString = myStreamReader.ReadLine();
                    Console.WriteLine(myString);
                    myProcess.Close();
    Mais myString est null ! Je ne comprend vraiment pas ! Est ce que cela peut venir du fait que le programme lancé retourne les valeurs dans un certain format ??

  4. #4
    Expert confirmé
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Par défaut
    Et si tu commençais par recopier le code sur la page de la msdn et changer juste la valeur du l'exe à appeler ?

    Le code que tu me montres y ressemble pas vraiment.

  5. #5
    Membre confirmé Avatar de Anto03
    Inscrit en
    Octobre 2005
    Messages
    155
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 155
    Par défaut
    Euh c'est justement ce que j'ai fait

    Ou alors on parle pas de la même chose, voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
                    Process myProcess = new Process();
                    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("flv.exe");
                    myProcessStartInfo.Arguments = GetParameters();
                    myProcessStartInfo.UseShellExecute = false;
                    myProcessStartInfo.RedirectStandardOutput = true;
                    myProcess.StartInfo = myProcessStartInfo;
                    myProcess.Start();
     
                    StreamReader myStreamReader = myProcess.StandardOutput;
                    string myString = myStreamReader.ReadLine();
                    Console.WriteLine(myString);
                    myProcess.Close();
    Et voici le code MSDN :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    Process myProcess = new Process();
    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("Process_StandardOutput_Sample.exe" );
    myProcessStartInfo.UseShellExecute = false;
    myProcessStartInfo.RedirectStandardOutput = true;
    myProcess.StartInfo = myProcessStartInfo;
    myProcess.Start();
     
    StreamReader myStreamReader = myProcess.StandardOutput;
    // Read the standard output of the spawned process.
    string myString = myStreamReader.ReadLine();
    Console.WriteLine(myString);
    myProcess.Close();
    La seule différence se trouve ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    myProcessStartInfo.Arguments = GetParameters();
    Mais sans ces arguments mon exe ne marche pas évidemment.

  6. #6
    Expert confirmé
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Par défaut
    Ah je regardais un autre code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     // Start the child process.
     Process p = new Process();
     // Redirect the output stream of the child process.
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.FileName = "Write500Lines.exe";
     p.Start();
     // Do not wait for the child process to exit before
     // reading to the end of its redirected stream.
     // p.WaitForExit();
     // Read the output stream first and then wait.
     string output = p.StandardOutput.ReadToEnd();
     p.WaitForExit();

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 25/11/2014, 11h57
  2. Process -- Récupérer les sorties d'un service
    Par Arnard dans le forum Débuter
    Réponses: 1
    Dernier message: 01/10/2009, 09h14
  3. Réponses: 6
    Dernier message: 12/04/2006, 14h53
  4. [JSP][Process] Récupérer message
    Par hedgehog dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 20/07/2005, 13h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo