java console怎么打开,java调用console程序打开文件的有关问题

当前位置:我的异常网» J2EE » java调用console程序打开文件的有关问题

java调用console程序打开文件的有关问题

www.myexceptions.net  网友分享于:2013-10-15  浏览:11次

java调用console程序打开文件的问题

我用如下的servlet来调用一个exe程序,exe程序见下。

当用tomcat运行这个servlet时发现任务管理器里闪了一下这个exe,但是exe没有打开文件,请问这是怎么回事?

package myHelloWorld;

import java.io.*;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.*;

import java.util.Scanner;

public class testopenfile extends HttpServlet

{

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws IOException,ServletException

{

PrintWriter out=response.getWriter();

out.write("\r\n");

out.write("

\r\n");

out.write("\r\n");

out.write("");

out.write("

\r\n");

out.print("going to capture data on sunxudong's pc");

String string_port_num;

String exetestpath="g:/sunAppPacket/openfile.exe";

String fileName="g:/sunAppPacket/netport_config.txt";

//

BufferedReader in=new BufferedReader(new FileReader(fileName));

string_port_num=in.readLine();

in.close();

run_exetest(string_port_num,exetestpath);

out.write("\r\n");

out.write("");

}//fun: doget

public static void run_exetest(String string_port_num,String exepath)

{

String line;

OutputStream stdin = null;

InputStream stderr = null;

InputStream stdout = null;

// launch EXE and grab stdin/stdout and stderr

Runtime rn = Runtime.getRuntime();

Process p = null;

try {

p = rn.exec(exepath);

stdin = p.getOutputStream ();

stderr = p.getErrorStream ();

stdout = p.getInputStream ();

// "write" the parms into stdin

line = string_port_num + "\n";

stdin.write(line.getBytes() );

stdin.flush();

stdin.close();

}catch (Exception e) {

}//catch

}//void run

}//class

exe程序如下,要求用户输入一段内容写到hello。txt里面

#include

using namespace std;

#include

#include

int main()

{

ofstream outfile;

char cCharContent[100];

printf("please input the content to write in\n");

scanf("%s",cCharContent);

outfile.open("hello.txt");

outfile<

outfile.close();

return 1;

}

------解决方案--------------------

换成bat调用文件就好了

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值