cmd如何在不单独启动的情况下作为java程序的一部分使用?
我想创建一个java程序,它可以从用户那里获取输入,并将该输入传递给cmd,然后获取并向用户显示输出。我在互联网上看到过很多例子,但它们只告诉我们如何从外部开始。但我不想开始。我想使用cmd作为程序的一部分,这样它就不会打开,而只会像对输入执行一些不可见的操作并返回输出一样工作。有人知道吗
我也尝试过在这个网站上搜索类似的问题,但没有找到。抱歉,如果是重复的
你可以在下面搜索框中键入要查询的问题!
我想创建一个java程序,它可以从用户那里获取输入,并将该输入传递给cmd,然后获取并向用户显示输出。我在互联网上看到过很多例子,但它们只告诉我们如何从外部开始。但我不想开始。我想使用cmd作为程序的一部分,这样它就不会打开,而只会像对输入执行一些不可见的操作并返回输出一样工作。有人知道吗
我也尝试过在这个网站上搜索类似的问题,但没有找到。抱歉,如果是重复的
# 1 楼答案
你可以用Runtime#exec来做这个。 下面的代码片段显示了如何读取在cmd中执行的特定命令的输出。exe
下面的示例显示了如何与流程交互