小编San*_*kar的帖子

读取从Java代码运行的C变量的值

我已经成功地从Java代码执行了C代码,但我有一个问题,我想将值读入C代码,其中C程序是从Java代码运行的.怎么做?

我的C代码如下.

int main()
{ 
    int op;
    printf("\n Hello World... ");
    printf("\n Enter any value : ");
    scanf("%d",&op);
    printf("\n The value entered is : %d",op);
    getch();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的java代码如下.

import java.io.*;
public class Test {
   public static void main(String args[]) {
      try {
            String s = " ";
            Process processCompile = Runtime.getRuntime().exec("e:/Sample.exe");

            BufferedReader stdInput = new BufferedReader(new
            InputStreamReader(processCompile .getInputStream()));
            // read the output from the command
            System.out.println("EXE OUTPUT");
            while ((s = stdInput.readLine()) != null) {
               System.out.println(s);
           }
        } catch(Exception …
Run Code Online (Sandbox Code Playgroud)

c java input

5
推荐指数
1
解决办法
116
查看次数

从Java代码调用C可执行文件后没有得到任何输出

我正在尝试从已经编译和执行的Java代码执行C代码,但是,我没有从可执行文件中获得任何输出.任何人都可以帮我完成这项任务吗?

代码如下.

public class Test {
    public static void main(String args[]) {
        try {
            Process processCompile = Runtime.getRuntime().exec("e:/Sample.exe");
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c java process runtime.exec

0
推荐指数
1
解决办法
376
查看次数

标签 统计

c ×2

java ×2

input ×1

process ×1

runtime.exec ×1