نمایش نتایج 1 تا 2 از 2

نام تاپیک: نحوه ی اجرا دستورات cmd

  1. #1
    کاربر دائمی
    تاریخ عضویت
    اسفند 1390
    محل زندگی
    Tehran,Iran
    سن
    27
    پست
    139

    Exclamation نحوه ی اجرا دستورات cmd

    دوستان در C++‎برای اجرا دستور cmdمینویسیم
    system ("دستور");
    اینجا باید چیکار کنیم؟

  2. #2

    نقل قول: نحوه ی اجرا دستورات cmd

    سلام... منم به اجرای دستورات cmdاحتیاج پیدا کردم،بعد از سرچ توی سایت های مختلف این تابع رو نوشتم، امیدوارم به دردتون بخوره:


    public void ExecuteCommand(string Command)
    {
    try
    {
    // create the ProcessStartInfo using "cmd" as the program to be run,
    // and "/c " as the parameters.
    // Incidentally, /c tells cmd that we want it to execute the command that follows,
    // and then exit.
    System.Diagnostics.ProcessStartInfo procStartInfo =
    new System.Diagnostics.ProcessStartInfo("cmd.exe", "/C" + Command);

    // The following commands are needed to redirect the standard output.
    // This means that it will be redirected to the Process.StandardOutput StreamReader.
    procStartInfo.RedirectStandardOutput = true;
    procStartInfo.UseShellExecute = false;
    procStartInfo.CreateNoWindow = true;
    // Now we create a process, assign its ProcessStartInfo and start it
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo = procStartInfo;
    proc.Start();
    // Get the output into a string
    string result = proc.StandardOutput.ReadToEnd();
    }
    catch (Exception objException)
    {
    MessageBox.Show("مشکلی در اجرای فرمان به وجود امد" + "\n" + "مشکل به وجود آمده: " + "\n" + objException.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }



    دستورت رو به این تابع می دی و برات اجراش می کنه.

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •