Bonjour à tous!

Je suis débutant en ASP bien sûr. J'ai tenté de chercher de l'info partout mais je n'ai pas trouvé exactement ce que je voulais.

J'aimerais appeller un script BATCH (ou une simple commande, c'est pareil dans mon cas) et récupérer ce que mon script affiche. Pour l'instant, j'arrive à afficher dans ma vue le retour de mon script, mais le problème est qu'il affiche aussi TOUTES les autres informations

Par exemple: je voudrais récupérer les valeurs d'un ipconfig (ou autre, peu importe).

J'appelle donc un batch:


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
<%
       string exec = "c:\\usr\\bin\\test.bat";
 
       // Get the full file path
       string strFilePath = Server.MapPath("usr\\bin\\");
       // Create the ProcessInfo object
       System.Diagnostics.ProcessStartInfo psi =
       new System.Diagnostics.ProcessStartInfo("cmd.exe");
       psi.UseShellExecute = false;
       psi.RedirectStandardOutput = true;
       psi.RedirectStandardInput = true;
       psi.RedirectStandardError = true;
       // Start the process
       System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
 
       // Open the batch file for reading
       //System.IO.StreamReader strm = 
       // System.IO.File.OpenText(strFilePath);
       System.IO.StreamReader strm = proc.StandardError;
       // Attach the output for reading
       System.IO.StreamReader sOut = proc.StandardOutput;
 
       // Attach the in for writing
       System.IO.StreamWriter sIn = proc.StandardInput;
 
       // Write each line of the batch file to standard input
       /*while(strm.Peek() != -1)
       {
       sIn.WriteLine(strm.ReadLine());
       }*/
       sIn.WriteLine(exec);
 
       strm.Close();
 
       // Exit CMD.EXE
       //     string stEchoFmt = "# {0} run successfully. Exiting";
 
       //        sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
 
       sIn.WriteLine("EXIT");
 
       // Close the process
       proc.Close();
 
       // Read the sOut to a string.
       string results = sOut.ReadToEnd().Trim();
 
       // Close the io Streams;
       sIn.Close();
       sOut.Close();
 
       // Write out the results.
       //string fmtStdOut = "<font face=courier size=0>{0}</font>";
       this.Response.Write(results);   
 
 %>
Ce qui m'affiche ça:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Robiwan>ipconfig

Windows IP Configuration


Ethernet adapter Local Area Connection:

...
...
Et j'aimerais garnir une variable avec ça:

Windows IP Configuration


Ethernet adapter Local Area Connection:
...
...
Bref, le retour de la commande uniquement =)



Des bonnes âmes pour m'aider?
Si c'est pas trop loin de Namur en Belgique je peux récompenser en Chimay bleue ;-)