简体   繁体   中英

How can I determine if a console app was executed from within a batch file?

I have a console application in which I need to detect whether or not it was executed from a command line, as opposed to from within a batch file. I want to protect

            Console.Write ( "Press any key to exit" );
            Console.ReadKey ( true );
            Console.WriteLine ( );

from executing when the app is executing from within a batch file.

您可以做一些疯狂的事情(例如获取父进程,查看它得到了什么参数,等等),但是如果您控制应用程序,则只需添加命令行参数,将其称为“批处理模式”,或者在调用程序时将其设为非互动的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM