Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Command Prompt από WinForm

Îåêßíçóå áðü ôï ìÝëïò Nassos.NET. Τελευταία δημοσίευση από το μέλος Nassos.NET στις 04-06-2008, 16:41. Υπάρχουν 2 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  04-06-2008, 16:02 42638

    Command Prompt από WinForm

    Καλησπέρα σε όλους,
    Ξέρετε πως μπορώ να τρέξω απο μία φόρμα μία εντολή στο command Prompt και να πάρω το αποτέλεσμα(π.χ "dir c:");
    Ευχαριστώ
    Νασος

    "Success is the ability to go from one failure to another with no loss of enthusiasm."
    Winston Churchill

    "Quality means doing it right when no one is looking."
    Henry Ford

  •  04-06-2008, 16:16 42640 σε απάντηση της 42638

    Απ: Command Prompt από WinForm

    Υποθέτω πως υπάρχουν δύο τρόποι:

    ο ένας είναι ο μπακαλίστικος που λέει ότι τρέχεις την εντολή όχι ως dir C: αλλά ως dir C: > C:\TEMP\temp.txt
    και μετά διαβάζεις από το πρόγραμμά σου το C:\TEMP\temp.txt

    ο άλλος τρόπος είναι στο process που θα σηκωθεί για να τρέξει το command prompt να πιάσεις το output stream και να του πεις πού να γράφει. Δυστυχώς δεν θυμάμαι πώς γίνεται αλλά ψάξε προς αυτή την κατεύθυνση.
  •  04-06-2008, 16:41 42641 σε απάντηση της 42640

    Απ: Command Prompt από WinForm

    Το βρήκα με Process,
    System.Diagnostics.ProcessStartInfo sinf =
            new System.Diagnostics.ProcessStartInfo("cmd", "dir c:\");
          // The following commands are needed to redirect the standard output. This means that it will be redirected to the Process.StandardOutput StreamReader.
          sinf.RedirectStandardOutput = true;
          sinf.UseShellExecute = false;
          // Do not create that ugly black window, please...
          sinf.CreateNoWindow = true;
          // Now we create a process, assign its ProcessStartInfo and start it
          System.Diagnostics.Process p = new System.Diagnostics.Process();
          p.StartInfo = sinf;
          p.Start(); // well, we should check the return value here...
          // We can now capture the output into a string...
          string res = p.StandardOutput.ReadToEnd();
    Ευχαριστώ

    "Success is the ability to go from one failure to another with no loss of enthusiasm."
    Winston Churchill

    "Quality means doing it right when no one is looking."
    Henry Ford

Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems