cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Determining current working folder consistently

ptc-953343
1-Visitor

Determining current working folder consistently

I'm working with an application that processes our content and produces an
IETM view. I want to launch the application and have it work on the
current document and have its context (for the second program) be the
folder the document is currently located.

It seemed like the the default was to use the directory where the current
document was. I got several successful runs of the program where this was
true. Then it started writing files to the desktop instead of the folder I
was using. Thought it might have something to do with double clicking the
document and launching Arbortext vs dragging the document into an existing
session, but that doesn't seem to make a difference.

Here is the sequence of events I'm trying to control:

1) For an open document, select a range of content that will be used later.
2) Create a Ant build properties file (always the same content).
3) Generate a new XML publication module using content selected in step 1
and create the file.
4) Launch build application (3rd party tool) that uses the
build.properties, the publication module, the document we started with in
step 1 and any associated graphics or referenced files.
4a) Application builds new directory in working folder, indexes files,
validates content, etc. It then zips the files together in the working
folder and then deploys them to another location on the locat machine.
5) Launch the viewer application.

So step 1 is achieved with some simple ACL. Steps 2, 3, 4 and 5 are all
done with Java methods - separate methods/calls.

Sometimes I see the files created in 2, 3 and 4 being created on my
desktop, other times I'm not sure where they are built. In step 4a the
process seems to get all the way to the point of zipping up the file and
then it hangs. At least that is where I get the last message in the
console. This process is basically running an Ant script. It seems that
once this process gets hosed, I'm then locked out of the editor.

Besides getting the working directory nailed down, I need to find a
graceful way to kill the process if the build fails.

The files in step 1 get here from a content managment system and may vary
by the user as to where this "working folder" is located.

ACL

function buildNSIV() {

caret first,first
caret 0,"<dmc>" -t
mark begin
caret 0,"</dmc>" -t
mark end
$title = $selection

java_static('NSIVbuild', 'genBuildProps');
java_static('NSIVbuild', 'genPubModule', $title)
response("Starting build, this takes a minute or two")
java_static('NSIVbuild', 'remove');
java_static('NSIVbuild', 'build');
response("Completed, now launching NSIV")
java_static('NSIVbuild', 'display');
# java_static('NSIVbuild', 'cleanup');
}


JAVA program

// Created by DevDaily.com

import java.io.*;
import java.util.Calendar;


public class NSIVbuild {

public static void genPubModule(String DMC) {

Calendar cal = Calendar.getInstance();

int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);


try{
// Create file
FileWriter fstream = new
FileWriter("PMC-test-78022-00000-00_000-00_en-US.xml");
BufferedWriter out = new BufferedWriter(fstream);

out.write("\n");
out.write(" out.write("ISO Character Entities 20030531//EN//XML\"
\"
out.write("%ISOEntities;\n");
out.write("]>\n");
out.write("<pm<br/>xmlns:xsi=\"
out.write("xsi:noNamespaceSchemaLocation=\"
out.write("xmlns:rdf=\"
out.write("xmlns:dc=\"
out.write("xmlns:xlink=\"
out.write("<idstatus>\n");
out.write("<pmaddres><pmc><modelic>test</modelic><pmissuer>78022</pmissuer>\n");
out.write("<pmnumber>00000</pmnumber><pmvolume>00</pmvolume></pmc>\n");
out.write("<pmtitle>Review Publish TEST " + month + "/" + day + "/" +
year + "</pmtitle>\n");
out.write("<issno issno="000"/>\n");
out.write("<issdate day="01" month="01" year="2000"/></pmaddres>\n");
// out.write("<issdate day=" + day + " month=" + month + " <br="/>year=" + year + "/></pmaddres>\n");
out.write("<pmstatus>\n");
out.write("<security class="01"/>\n");
out.write("<rpc></rpc>\n");
out.write("<actref><refdm></refdm></actref><applic><displaytext></displaytext>\n");
out.write("</applic>\n");
out.write("<qa>\n");
out.write("<unverif/></qa></pmstatus>\n");
out.write("</idstatus>\n");
out.write("<content>\n");
out.write("<pmentry>\n");
out.write("<title>Review Publish Results " + cal.getTime() +
"</title>\n");
out.write("<refdm>\n");

out.write(DMC);

out.write("</refdm>\n</pmentry>\n</content>\n</pm>\n");

//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}


public static void genBuildProps() {
try{
// Create file
FileWriter fstream = new FileWriter("build.properties");
BufferedWriter out = new BufferedWriter(fstream);
out.write("ietp.pm.main=PMC-test-78022-00000-00_000-00_en-US.xml\n");

//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}


public static void build() {

String s = null;

try {

String[] commands = new String[]{ "C:\\Program
Files\\nsiv3.1.13\\bin\\makedoc.bat", "deploy"};

Process p = Runtime.getRuntime().exec(commands);

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));

// read the output from the command

System.out.println("BUILD PROCESSING:\n");
System.out.println("Here is the standard output of the
command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command

System.out.println("Here is the standard error of the command
(if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}

public static void remove() {

String s = null;

try {

String[] commands = new String[]{ "C:\\Program
Files\\nsiv3.1.13\\bin\\nsiv.bat",
"-Dnsiv.ietp=test-78022-00000-00_000-00_en-US", "remove"};

Process p = Runtime.getRuntime().exec(commands);

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));

// read the output from the command
System.out.println("REMOVE PROCESSING\n");
System.out.println("Here is the standard output of the
command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command
System.out.println("Here is the standard error of the command
(if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}

}

public static void display() {

String s = null;

try {

String[] commands = new String[]{ "C:\\Program
Files\\nsiv3.1.13\\bin\\nsiv-browse.bat"};


Process p = Runtime.getRuntime().exec(commands);

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));

// read the output from the command
System.out.println("DISPLAY PROCESSING\n");
System.out.println("Here is the standard output of the
command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command
System.out.println("Here is the standard error of the command
(if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}

}


public static void cleanup() {

String s = null;

try {

String[] commands = new String[]{ "del", "build.properties"};
Process p = Runtime.getRuntime().exec(commands);

System.out.println("DISPLAY PROCESSING\n");
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}


try {

String[] commands = new String[]{ "del",
"test-78022-00000-00_000-00_en-US.nci"};
Process p = Runtime.getRuntime().exec(commands);

System.out.println("DISPLAY PROCESSING\n");
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}


try {

String[] commands = new String[]{ "del",
"PMC-test-78022-00000-00_000-00_en-US.xml"};
Process p = Runtime.getRuntime().exec(commands);

System.out.println("DISPLAY PROCESSING\n");
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}


try {

String[] commands = new String[]{ "del", "/Q", ".nsiv"};
Process p = Runtime.getRuntime().exec(commands);

System.out.println("DISPLAY PROCESSING\n");
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}

}


}


2 REPLIES 2

Hi Dan--

Try using the Arbortext "cd" command in your script before you start
your process (step 0) to set the current directory to what you want it
to be. For example, if you want the working directory to be the
directory containing the current document, try modifying your function
something like this:


function buildNSIV() {

local wd = dirname(doc_path());
cd $wd;
caret first,first
caret 0,"<dmc>" -t
....
}

FWIW, the working directory can be changed by selecting any kind of file
via the file selector, as well as some other more subtle ways.

As for killing a hung java process, you might try using
java_static_modal(), which runs the java static method in its own
thread. That way you could have a toolbar button or some other control
in Arbortext that could terminate that process. (Tracking and managing
threads is probably beyond what can be explained in an email, but
hopefully this will get you going down the right path.)

--Clay

Clay Helberg
Senior Consultant
TerraXML

thanks, I was wondering if people have seen the random changing of
the working directory as I thought it was supposed to follow the
current document. Your fix got the files writing consistently, but I
have something funny going on with the 3rd party app I'm calling. For
some reason it is stopping near the end with no error. Yet if I run
it in a command window it runs just fine. Need to do some more
research into what is going on.

I'll definitey need to make it more bullet proof so it doesn't hang
the editor up like this. Your tips on that will help.

..dan

Announcements

Top Tags