PDA

View Full Version : آموزش: اجرای خودکار یک فرمان در cmd



amir11205
چهارشنبه 31 شهریور 1389, 21:00 عصر
سلام به دوستان عزیز
به تاپیک قبلیم با آدرس زیر که کسی جواب نداد
http://barnamenevis.org/forum/showthread.php?t=248202

حالا یه سوال دیگه دارم
من می خوام یه کد بنویسم که تو اون cmd باز شه و یک دستور به طور خودکار عمل کنه
باید چیکار کنم
اگه میشه کمکم کنید
در ضمن این دستور فقط در cmd اجرا میشه.
دستورم یک عمل export/import تو اوراکله
ممنونم ازتون

linux
چهارشنبه 31 شهریور 1389, 21:12 عصر
http://www.codeproject.com/KB/cs/Execute_Command_in_CSharp.aspx

amir11205
چهارشنبه 31 شهریور 1389, 21:44 عصر
http://www.codeproject.com/KB/cs/Execute_Command_in_CSharp.aspx
میشه یه توضیحی بدین
چون من که نفهمیدم که دستورمو باید کجا بنویسم

flash118
چهارشنبه 31 شهریور 1389, 21:48 عصر
دوست عزیز کجاش مشکل دارین بفرمایید بررسی کنیم البته با اجازی linux عزیز

amir11205
چهارشنبه 31 شهریور 1389, 22:02 عصر
دوست عزیز کجاش مشکل دارین بفرمایید بررسی کنیم البته با اجازی linux عزیز
سلام
والا من میخوام اینجور باشه
1) cmd باز شه
2) فرمان موردنظر به صورت خودکار تایپ شده و به صورت خودکار اجرا بشه
3) تا زمان اجرای فرمان cmd باز باشه و همین که تموم شد بسته شه
ببخشید که اینجور گفتم
از کد بالا هم چیزی نفهمیدم

Saman_12
پنج شنبه 01 مهر 1389, 00:06 صبح
از دستور Shell ء VB استفاده کن اول باید ماکروسافت ویژوال بیسیک رو رفرنس کنی :

Microsoft.VisualBasic.Interaction.Shell("PERMISSION", "Styal", "Wait", "Time Out")

moh_mov
پنج شنبه 01 مهر 1389, 07:26 صبح
ایده من :
یک batch file بساز و اونجا دستورت رو بنویس بعد اون رو ذخیره کن ، با دستورات فکر کنم process تو c# می تونی اجراش کنی.
cmd باز میشه و کار انجام میشه.
تو batch file که بلدی؟
یه notepad باز کن و توش دستور رو بزن و بعدش با .bat ذخیره کن!

linux
پنج شنبه 01 مهر 1389, 19:54 عصر
میشه یه توضیحی بدین
چون من که نفهمیدم که دستورمو باید کجا بنویسم

/// <summary>
/// Executes a shell command synchronously.
/// </summary>
/// <param name="command">string command</param>
/// <returns>string, as output of the command.</returns>
public void ExecuteCommandSync(object 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", "/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;
// Do not create the black window.
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();
// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
// Log the exception
}
}
این قسمت را به برنامه خودت اضافه کن هر موقع که لازمش داشتی فراخوانی کند توی commnad هم دستوری که لازم داری بنویس