PDA

View Full Version : سوال: ارسال آرایه به صورت پارامتر از طریق CMD



nunegandom
یک شنبه 22 مرداد 1391, 16:12 عصر
با سلام
این کد

using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace Main
{
static class Program
{
/// <summary>
/// code[0] => "completed"
/// code[1] => filename with extention
/// </summary>
/// <param name="code">code[0] & code[1]</param>
[STAThread]
static void Main(string[] code)
{
if (code == null || code.Length == 0)
{
string _directory = Environment.CurrentDirectory;
Process.Start("cmd.exe", _directory+"\""+code[1]+" StartSplashing");
}
// else if (code[0] == "completed")
// {
Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState .NoneEnabled;
// Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new MainForm());
// }
}
}
}

چطوری پارامتر به صورت آرایه ارسال کنم؟ حالا با CMD یا دستورات C# میخام از یک exe به یه exe دیگه پارامتر به این صورت بفرستم string[] و بعد از اون چطوری خونه ۱ و ۲ و ۳ شو تشخیص بدم؟
مثلا

code[0] code[1]
:لبخند: ممنون اگه کسی جوابی داره بده

Mahmoud.Afrad
یک شنبه 22 مرداد 1391, 17:15 عصر
برای تشخیص کافیه null و صفر بودن طول را بررسی کنید.
[STAThread]
static void Main(string[] code)
{
if (code != null && code.Length > 1)
{
Process.Start("cmd.exe", Environment.CurrentDirectory + "\"" + code[1] + " StartSplashing");
}
else if (code != null && code.Length != 0 && code[0] == "completed")
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true );
Application.Run(new Form1());
}
}
در cmd یا ایجاد شورتکات با ارسال پارامتر میتونید برنامه را اجرا کنید مثلا
AppName completed

nunegandom
یک شنبه 22 مرداد 1391, 17:28 عصر
نه... :( این جواب من نبود
من میخوام پارامتر ارسال کنم و این سمت مقدار رو بخونم... اینجوری که نمیشه :| راهی نیست که آرایه ارسال کنم؟
اگه نیست تا راهم رو تغییر بدم :(