Run shell commands in running executable

For the software package I am working on, I use the Stanford Natural Language Parser. The parser can be ran by calling a Linux shell command which looks like this:

$ bash lexparser.sh input.txt

The parser then loads the parser and parses the sentences found in input.txt. The loading of the parser, however, takes about 4 seconds. Another possibility is:

$ bash lexparser.sh -

Using this function, the parser is loaded and waits for input, which can than be directly typed into the terminal.

Because the program I am creating needs to work in less than 4 seconds, I want to use the second option. Has anyone got any idea how to give the terminal input while allready running an executable in that terminal?
The second option isn't any faster, it just reads from stdin rather than a file.
Well, my program needs to wait for input and when given, it needs to run the given sentence in the parser. So, when the parser is allready loaded, it can give output faster. That's why I want to use the second option.
Have you looked at that shell script to see what it's doing?
I tried, but didn't really understand it. The sh file looks like this:




#!/usr/bin/bash
#
# Runs the English PCFG parser on one or more files, printing trees only

if [ ! $# -ge 1 ]; then
echo Usage: `basename $0` 'file(s)'
echo
exit
fi

scriptdir=`dirname $0`

java -mx600m -cp "$scriptdir/*:" edu.stanford.nlp.parser.lexparser.LexicalizedParser \
-outputFormat "typedDependencies" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz $*



Still, I don't think this is the right approach, because the parser needs to be loaded and running, waiting for input.

Right now, I use the first approach in my program, with popen. This runs the command given, gives the output and than stops, but I need to run a command which runs an executable and later on give more input to the same terminal.
For this, I think the boost.process library is suitable.
The reason it sometimes takes as long as four seconds to run is because it's Java. That time is the time it takes the JVM to load. No clever scripting or wrapping with BASH or C++ is going to fix that.
Topic archived. No new replies allowed.