简体   繁体   English

我可以使用通过“ Runtime.getRuntime()。exec(Cmdline)”运行的servlet来运行另一个程序(exe文件)并写入和读取文本文件吗?

[英]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.

相关问题 如何从使用Runtime.getRuntime()。exec(cmdLine)执行的Java程序中从netcat侦听器子进程中获取std输出? - How do I grab std output from a netcat listener subprocess from my Java program that I executed using Runtime.getRuntime().exec(cmdLine)? 如何使用Runtime.getRuntime()。exec运行任意Java程序? - How to use Runtime.getRuntime().exec to run an arbitrary Java program? 如何使用Runtime.getRuntime()。exec()在项目中运行程序? - How to use Runtime.getRuntime().exec() to run a program within project? 无法从Runtime.getRuntime()。exec(..)启动Steam.exe - Cannot start Steam.exe from Runtime.getRuntime().exec(..) Runtime.getRuntime().exec(command) - 无法运行程序,错误=2,没有那个文件或目录 - Runtime.getRuntime().exec(command) - Cannot run program, error=2, No such file or directory Runtime.getRuntime()。exec(“path to file”)运行,但程序行为很奇怪 - Runtime.getRuntime().exec(“path to file”) runs, but program acts strange Runtime.getRuntime()。exec - >无法运行程序CreateProcess error = 2,系统找不到指定的文件 - Runtime.getRuntime().exec -> Cannot run program CreateProcess error=2, The system cannot find the file specified Runtime.getRuntime().exec() 导致 java.io.IOException: Cannot run program... no such file or directory - Runtime.getRuntime().exec() results in java.io.IOException: Cannot run program ... no such file or directory 如何使用 java (Runtime.getRuntime().exec()) 启动 python 程序 - How to start a python program using java (Runtime.getRuntime().exec()) Servlet 程序无法使用 Runtime.getRuntime() 启动命令提示符 - Servlet program fails to launch command prompt using Runtime.getRuntime()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM