从CMD执行一个方法 [英] Execute a methode from CMD
问题描述
我有一个小的Winform,显示带有一些数据的DatagridView
我还有一个按钮,用于检查一行中每个单元格的字符串格式是否相同。
现在我需要能够从命令行执行特定的StringFormat_check Methode。我不需要显示DatagridView,只需要进行检查并返回类似于true或false的返回值。
我需要集成该过程在特定的批处理文件中。
说实话我不知道从哪里开始和做什么
任何帮助都会受到赞赏。
我的尝试:
...... .................................................. ....
您可以做的是编辑WinForms应用程序的Main方法,如果收到某个命令行参数,请说/ checkOnly
,然后只调用StringFormat_check方法:
[STAThread]
static void Main( string [] args)
{
if (args.Length > 0 && args [ 0 ] == / checkOnly)
{
// 使用StringFormat_check做你的东西
}
else
{
// 保留默认的自动生成代码,可能如下所示:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new Form1());
}
}
从您的批处理文件中,按如下方式调用您的应用程序:
< pre lang =text> YourWinFormsApp.exe / checkOnly<如果需要,可能还有其他参数>
使用C#应用程序增强批处理文件功能:第一部分 [ ^ ]
Hi, I have a small Winform that shows a DatagridView with some data
Also I have a button that check if the String Format of each cell in one row is the same or not.
Now I need the ability to execute only that specific StringFormat_check Methode from a command line. I don't need to show the DatagridView, only to do the check and having a return like true or false or something like that.
I need to integrate that process in a specific Batch file.
to be honest I have no idea from where to start and what to do
any help would appreciated.
What I have tried:
............................................................
What you can do is edit the Main method of your WinForms application and if you receive a certain command-line argument, say/checkOnly
, then only call the StringFormat_check method:
[STAThread] static void Main(string[] args) { if (args.Length > 0 && args[0] == "/checkOnly") { // do your stuff with StringFormat_check } else { // leave the default auto-generated code here, that probably looks like: Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }
And from your batch file, call your application like this:
YourWinFormsApp.exe /checkOnly <maybe other arguments here if needed>
Enhance Batch File Functionality With C# Application : Part I[^]
这篇关于从CMD执行一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!