This site requires JavaScript, please enable it in your browser!
Greenfoot back
vicbuenaventura
vicbuenaventura wrote ...

2016/3/11

Execute another program with argument from java

vicbuenaventura vicbuenaventura

2016/3/11

#
Hello, I'm using Greenfoot on Mac OSX as user interface to open another program (the program is called CLIPS expert system). I'm able to do it with the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void act()
{
   if (Greenfoot.mouseClicked (this))
      {
         try
            {      
               Process process = Runtime.getRuntime().exec("open -a clips");
            }
          catch (Exception ex)
             {
                ex.printStackTrace();
             }
      }
}
But I also want to pass an argument in the form of a batch file (entitled "runfile.txt") so that when CLIPS opens, I want it to automatically execute the commands I've written in the batch file (such as loading a construct from a file, resetting, running, and exiting CLIPS). I tried the following code but it did not do anything:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void act()
{
   if (Greenfoot.mouseClicked (this))
      {
         try
            {      
               Process process = Runtime.getRuntime().exec("open -a clips -f runfile.txt");
            }
          catch (Exception ex)
             {
                ex.printStackTrace();
             }
      }
}
Additionally, I tried the following code and it did not do anything either:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void act()
{
   if (Greenfoot.mouseClicked (this))
      {
         try
            {      
               String[] cmdArray = new String[2];
               cmdArray[0] = "open -a clips";
               cmdArray[1] = "batch runfile.txt";
               Process process = Runtime.getRuntime().exec(cmdArray)
            }
          catch (Exception ex)
             {
                ex.printStackTrace();
             }
      }
}
Does anyone know how to code what I'm trying to accomplish? Thanks, Vic
You need to login to post a reply.