简体   繁体   English

使用包含换行符的字符串参数启动外部程序

[英]Launch external program with string arguments containing line breaks

From a .Net WinForms C# application I need to invoke another program (which is also a .Net WinForms C# application if that makes any difference) with string arguments containing line break / new line characters. .Net WinForms C#应用程序中,我需要使用包含换行符/换行符的字符串参数来调用另一个程序(如果有任何区别,它也是.Net WinForms C#应用程序)。

If I use Process.Start() method (in the calling program ) and Environment.GetCommandLineArgs() (in the called program ) to do this, it is equivalent to running the program from the command line. 如果我使用Process.Start()方法(在调用程序中 )和Environment.GetCommandLineArgs() (在调用程序中 )来执行此操作,则等效于从命令行运行该程序。 In this case, will be able to pass string arguments containing line break / new line characters without running into issues on either side? 在这种情况下,将能够传递包含换行符/换行符的字符串参数而不会遇到任何问题?

Answered By – IInspectable Aug 17 at 16:07

Process.Start() calls CreateProcess() . Process.Start()调用CreateProcess() There is no command line interpreter involved. 没有涉及命令行解释器。 This is not at all the same as running a process from the command line. 这与从命令行运行进程完全不同。 The command line interpreter imposes restrictions on valid characters in a command line. 命令行解释器对命令行中的有效字符施加了限制。 You cannot pass a newline character through the command line (but you can through a call to CreateProcess() ). 您不能通过命令行传递换行符(但是可以通过调用CreateProcess() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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