且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用参数运行控制台应用程序

更新时间:2023-02-17 21:07:48

这是一个堆栈溢出问题,可以回答您的问题:

http://***.com/questions/2593313/how-to- execute-console-application-from-windows-form [ ^ ]

基本上,您使用System.Diagnostics.Process.Start方法来调用应用程序并传递所需的参数.
Here is a Stack Overflow question that has the answer to your question:

http://***.com/questions/2593313/how-to-execute-console-application-from-windows-form[^]

Basically, you use the System.Diagnostics.Process.Start method to call your app and pass in the parameters you want.


这实际上取决于H3LTON可执行文件的功能.
It all really depends what your H3LTON executable does.

  1. 是否可以像python shell那样生动地运行命令?如果是这种情况,我将进行处理,以使System.Diagnostic.Process与输入流重定向一起运行.输入流将是 System.IO.StreamReader [ ^ ] TextBox的字符串内容.
  2. 如果可执行文件可以从文件中读取程序.只需将TextBox的内容写入文件,然后使用文件名作为参数调用H3LTON可执行文件.
  3. 如果您可以直接将命令指定为命令行参数,也可以这样做,但是您应该知道命令行的总长度是有限的.我不确定目前该限制在哪里,但是如果有人在该TextBox中输入了一个真正的大程序,那可能会削弱设置的功能.

  1. Is it something that runs commands interactlively like a python shell? If that should be the case I''d work it so that the System.Diagnostic.Process is run with input stream redirection. The input stream would then be a System.IO.StreamReader[^] that would be fed from the string content of your TextBox.
  2. If your executable can read a program from a file. Just write the content of the TextBox to a file and call your H3LTON executable with the filename as the parameter.
  3. If you can specify commands directly as a command line parameter you can also do that, but you should know that the total length of the command line is limited. I''m not quite sure where that limit is right now, but there is one which might cripple the functionality of your setup if somebody entered a real big program into that TextBox.



因此,无论选择哪种方法,都应该了解您要实现的目标以及每种解决方案的优缺点.将代码保存到具有不断变化的临时文件名的中间文件中的优点是,在清除临时存储空间之前,用户输入的所有程序都不会丢失.这可以被认为是一个功能:).

问候,

曼弗雷德(Manfred)



So which ever method you choose you should be aware of what exactly you are trying to achieve and the benefits and drawbacks of each solution. Saving the code into an intermediate file with a constantly changing temporary filename has the advantage that all the programs a user entered will not be lost until the temporary storage space is cleard. This could be considered a feature :).

Regards,

Manfred