Moeiz Riaz
Moeiz Riaz

Reputation: 305

executing java program with lua posix execp

I am having trouble using lua's posix.execp() function to execute a java program within a child process. I want to be able to create pipes and have the processes communicate with each other. Hence why I want to use luaposix .For some reason it interprets all forward slashes as periods in the classpath. I am not entirely sure if I am setting this up right. I am wondering if I am doing something wrong in the table that I am giving to the execp() function.

argjava={}
argjava[0]="java"
argjava[1]="-cp"
argjava[2]="/home/joeA/tree-lstm/lib/:'
argjava[3]="/home/joeA/tree-lstm/lib/stanford-parser/stanford-parser.jar:"
argjava[4]="/home/joeA/tree-lstm/lib/stanford-parser/stanford-parser-3.5.1-models.jar"
argjava[5]="ConstituencyParser" 
argjava[6]="-tokenpath"
argjava[7]="tokens.tmp"
argjava[8]="-parentpath"
argjava[9]="parents.tmp"
argjava[10]=nil

posix.execp("java",argjava)

I want it to make it look like this:

java -cp /home/joeA/tree-lstm/lib/:/home/joeA/tree-lstm/lib/stanford-parser/stanford-parser.jar:/home/joeA/tree-lstm/lib/stanford-parser/stanford-parser-3.5.1-models.jar ConstituencyParse -tokpath tokens.tmp -parentpath parents.tmp

This is an error that comes up:

Error: Could not find or load main class .home.joeA.tree-lstm.lib.stanford-parser.stanford-parser.jar:

Upvotes: 1

Views: 281

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81052

Each value in the argjava almost certainly becomes an independent argument on the resulting command line.

So you can't split up the parts of the argument to -cp like that or it ends up being three arguments only one of which is the argument to -cp and the other two are things to load (hence the error).

Try putting the paths and jars in a single string/value in the table.

argjava={
    [0]="java",
    "-cp",
    "/home/joeA/tree-lstm/lib/:/home/joeA/tree-lstm/lib/stanford-parser/stanford-parser.jar:/home/joeA/tree-lstm/lib/stanford-parser/stanford-parser-3.5.1-models.jar",
    "ConstituencyParser",
    "-tokenpath",
    "tokens.tmp",
    "-parentpath",
    "parents.tmp",
}

Upvotes: 3

Related Questions