Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5202 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted (edited)

Don't know if you can help with this. I am trying to use the shell to covert an .rtf file to .pdf

the script is:

cupsfilter /Volumes/Macintosh HD/Users/pracau/Desktop/CHCAD3A Activity.rtf>>/Volumes/Macintosh HD/Users/pracau/Desktop/CHCAD3A Activity.pdf

It does the job when I use the terminal but I get an Unrecognised MIME error when I use RunShellScript.

The problem may well be syntaxical. Any ideas.

_______________

edit

The error message I get is:

java.lang.Exception: cupsfilter: Unable to determine MIME type of "/Volumes/Macintosh HD/Users/pracau/Desktop/CHCAD3A Activity.rtf>>/Volumes/Macintosh HD/Users/pracau/Desktop/CHCAD3A Activity.pdf"!

To make things more interesting I tried an old faithful, the now nonexistent but still functional Zippshell plugin.

It worked so my problem is solved, allbeit in an odd way. There must be a problem with the java script which might be worth looking into.

By the way I think that ScriptMaster is a great addition to my world. Thanks very much

Edited by Guest
Posted (edited)

Sorry thats not it

Just tried it again but I had already tried just about every variant in syntax I could think of.

And it does work with the Terminal and with the Zippshell plugin.

Edited by Guest
got the plugin name wrong. corrected
Posted (edited)

Sorry Jesse, but this is still an issue.

Even though I can use the zippshell plugin to accomplish what I need to do, cluttering up my extensions folder with plugins (including unsupported ones like zippshell) does not seem desirable.

Could you or someone else check it out because it is not an OS problem; the Terminal handles the command (so does zippshell). It does seem to be a problem with the Scriptmaster module... and that is of some concern.

Thanks for your attention.

Edited by Guest
Posted (edited)

I don't think this problem is with ScriptMaster so much as it is with the java exec.runtime function.

Your shell command involves redirection, but to redirect from exec.runtime, you need to set up stream redirection -- either in Java OR by running your command in a command processor such as bash on Mac or DOS on Windows.

This article, aptly entitled "When exec.runtime won't)", is an excellent resource on several of the pitfalls with calling the shell from java http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4 -- though it's a bit dated and pertains more to Windows.

In Windows, you can redirect standard output to a file, e.g. code below redirects the output of the directory command.

It works because the command executed, cmd, is a command processor capable of redirection.

If, in contrast, I go to Start|Run in Windows, and enter

ping localhost >> c:test22.txt

It will NOT redirect ping output, because the command wasn't run in a command processor; if in contrast, I enter the identical ping command in DOS, then it will redirect. I'm not as familiar with UNIX, but I'm assuming you can alternately achieve redirection, by preceding the command with bash, or tcsh, thereby, eliminating the need for the Java to do the redirection?

I'm assuming you would achieve this on Mac OSX with

Process p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ls > Redirectedoutput.txt"}); but I don't have a Mac handy for testing; can you respond if this works or requires any modifications? This seems to be a bit easier invocation overall, in that -c will cause the bash instance to just process the next string as a command without any tokenizing.

The below code achieves redirection in Windows.

Also, the runshellscript example that is included in the latest scriptmaster download, doesn't seem to run on Windows, even when I change command to cmd /c DIR for instance -- I believe I understand why. The tokenizer is NOT the problem. Rather, it hangs at process.waitfor(). This is because the buffer overflows with a DIR command, and the process blocks, so it can never get past this; the buffer must be reading as process runs, or it will overflow; you cannot do a process.waitfor() prior to reading the command's output or it will hang with just about any Windows command I tried. The buffer must be shorter on Windows than Mac. Even the PATH commands seems to overflow it. So I'd recommend reading the output and error *before* the waitfor() and exitvalue. Making that change, fixes the example script in Scriptmaster so that it is windows-friendly, at least Vista.

String[] command = new String[6];

command[0] = "cmd";

command[1] = "/C";

command[2] = "dir";

command[3] = "c:";

command[4] = ">>"

command[5] = "c:test10.txt"

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

BufferedReader stdInput = new BufferedReader(new

InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new

InputStreamReader(p.getErrorStream()));

// read the output from the command

String s = "";

String a = "";

while ((s = stdInput.readLine()) != null) {

a = a + s + "n";

}

// read any errors from the attempted command

while ((s = stdError.readLine()) != null) {

a = a + s + "n";

}

return a;

Edited by Guest
OSX exec parameters; SM example script clarification
Posted

Thanks fseipel for this reply.

Unfortunately I'm not a java geek at all.

Rather I wanted to accomplish something that seems simple , but apparently is not.

That is to convert a .doc file to .pdf on the fly so that it can be viewed in the web viewer.

Strangely this seem more problematic for a novice like me on the Mac platform than on Windows. There are programs that give the capacity to do this from the DOS command line... but not for OSX.

But I found out you could do it by first converting it to .rtf using the textutil OSX command, then using the cupfilter command to convert the .rtf file to .pdf. Very handy... but I was surprised that the Scriptmaster PerformShellScript module couldn't perform the cupsfilter script whereas the Terminal and another plugin could.

Sorry, but I don't have the faintest idea how I would go about trying out your suggestion. It deals with what goes on 'under the bonnet' whereas what I need is to be able to drive the car. Thanks for it though.

Maybe Scriptmaster developers could follow it up.

Posted

Hello Pracau, I did some more research into this and I think I have a better solution. Define these two input parameters:

command (this is the actual command you want to run)

waitForResult ( either 'true' or 'false' )

And then try it with this Groovy code:


String[] cmds = ["/bin/sh", "-c", command];

Process process = Runtime.getRuntime().exec( cmds );

if( Boolean.valueOf( waitForOutput ) ) {

	if( process.waitFor() == 0 ) {

		return process.getInputStream().getText();

	} else {

		throw new RuntimeException( process.getErrorStream().getText() );

	}

} else {

	return "";

}

This topic is 5202 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.