1

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:

2
  • I assume each value in argjava becomes an independent argument to java on the command line. So you can't split up the parts of the argument to -cp like that. Try putting the paths and jars in a single string/value. Commented Oct 29, 2015 at 17:25
  • That works! I didn't realize that each element in argjava becomes independent. Commented Oct 29, 2015 at 17:39

1 Answer 1

3

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",
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.