如何使用参数运行控制台应用程序 [英] How to run console apps with an argument

查看:190
本文介绍了如何使用参数运行控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经完成了我的编程语言,这一次它从文件中读取并使用了args [0],但我想为此创建一个IDE(我认为它被称为).它的意思是打开程序,在文本框中键入所有代码,然后按运行按钮或类似的按钮,然后打开一个名为"H3LTON"的.exe文件(我的编程语言名称),然后将代码从文本框作为args [0]发送到它,以便它可以运行它.这可能吗?如果是这样,我该怎么办?您能给我一个代码示例吗?

hey guys,

i have finnished my programming language, this time it reads from a file and uses the args[0] thingy, but i want to make an IDE(i think it is called) for it. What it is meant to do is you open the program, you type in all the code into a textbox and then you press a run button or something like that and it open up a .exe file called ''H3LTON''(my programming language name) and it then sends the code from the TextBox to it as the args[0] so that it can run it. is this possible? if so, how can i do it? can you please give me a code example?

推荐答案

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

http://stackoverflow.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://stackoverflow.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


这篇关于如何使用参数运行控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆