[英]Can I use a servlet using “Runtime.getRuntime().exec(Cmdline)” to run another program (exe file) and write to and read from text files?
I have an eclipse project (let's call it myapp.java) that is a java SWT GUI with a few text boxes and push buttons. 我有一个Eclipse项目(我们称其为myapp.java),它是一个带有几个文本框和按钮的java SWT GUI。 When the user enters the required information, it writes a text file and creates a string called command-line . 当用户输入所需的信息时,它将编写一个文本文件并创建一个名为command-line的字符串。 It then uses the run-time command: 然后,它使用运行时命令:
Process process = Runtime.getRuntime().exec(Cmdline);
to execute another program, written in C (lets call this myapp.exe). 执行另一个用C编写的程序(让我们称之为myapp.exe)。 The command line contains myapp with various command line options. 命令行包含带有各种命令行选项的myapp。 This program reads the inputfile.txt and writes and outputfile.txt. 该程序读取inputfile.txt并写入和outputfile.txt。
The java program then copies the file outputfile.txt into a window. 然后,Java程序将文件outputfile.txt复制到窗口中。
Can I make this application into a dynamic web application and place these two programs on a web-site and execute them on the host machine? 我可以将该应用程序制作成动态Web应用程序并将这两个程序放在网站上并在主机上执行它们吗? If so, what are the steps involved? 如果是这样,涉及哪些步骤? I will need to run an exe file on the host machine from a java program and read and write text files on the same machine. 我将需要通过Java程序在主机上运行exe文件,并在同一台计算机上读取和写入文本文件。
The cmd executing part will be the same as for SWT. cmd执行部分将与SWT相同。 It should be no problem to reuse your existing code, if the SWT GUI and the cmd execution logic are are nicely separated. 如果SWT GUI和cmd执行逻辑很好地分开了,那么重用您现有的代码应该没问题。 Of course the GUI (web) part is completely different. 当然,GUI(Web)部分是完全不同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.