Executing a batch from a script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2007 05:14 AM
My alfresco is installed on windows, and I have created a space called incoming. There is a rule on this space, that distribute the files from it to their respective space.
In a specific situation, I want to execute a batch file (.bat), that loads the content of the file into the DB (oracle), using sqlldr, and then move it.
My script is written in JavaScript, and runs on the server side.
I tried the example below:
var oShell = new ActiveXObject("Shell.Application");var commandtoRun = "calc.exe";// Invoke the execute method.oShell.ShellExecute(commandtoRun, "", "", "open", "1");
That has raised a ScriptException, with the error "ActiveXObject is not defined".
Is there a way to do it??
This is really important, and I have to demonstrate this tomorrow.
Please let me know what is the best way to do it..
Shlomi
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2007 05:50 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2007 03:51 AM
As you said your javascript "runs on the server-side" - it does not have access to any Browser related objects or Browser JavaScript APIs such as ActiveXObject.
I see, in that case, what are my options with integrating a third party application (on the server side) that needs to execute by a rule on a specific file? (say when the file arrives, and have a certain extension to its name, run a third party application, that uploads this file to our database).
Regards,
Shlomi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2007 07:42 AM
Thanks,
Kevin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2008 11:19 AM
That is exactly what I have done, and it worked perfectly.
Good day,
Shlomi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2009 10:18 AM
I need to perform the same task (run .bat file), but don't have much experiences with Java and JavaScript and from above text I didn't get it.
Could you please write some short example how to achieve it?
Thank you
Ales
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2009 09:39 AM
uncle Gyro's 2 ct for the weekend:
Usually (say in 9 out of 10 cases) it is bad idea to call out to external processes from Java, especially on the server side: you have to take care of OS pecularities, blocking behaviour, security and the like. In an EJB environment this isn't even allowed for that reasons (usually in a non-strict sense, all application servers i know dont thwart that…).
In most cases, Java offers a more "javaish", more straight way to perform task - for the SQLLDR case it would be to open a straight JDBC connection and feed the database!
Said that, of you absolute must, Runtime.exec() or class ProcessBuilder are your friends. But beware: when using exec(), you have to take care to spawn two consumer threads to gobble the subprocess' output streams, otherwise your exec() call may block. I suppose there are some helper classes out there.
HTH
Gyro

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2009 07:37 AM
maybe I am missing some important part of knowledge…
I tried to execute this very short script:
var r = Runtime.getRuntime();r.exec("calc.exe");
And received the error
org.alfresco.error.AlfrescoRuntimeException: 10300137 Error during command servlet processing: 10300136 Failed to execute script 'workspace://SpacesStore/866c3275-531c-4823-8ad2-14f2a622baac': 10300135 ReferenceError: "Runtime" is not defined. (workspace://SpacesStore/866c3275-531c-4823-8ad2-14f2a622baac#13)caused by:org.alfresco.scripts.ScriptException: 10300136 Failed to execute script 'workspace://SpacesStore/866c3275-531c-4823-8ad2-14f2a622baac': 10300135 ReferenceError: "Runtime" is not defined. (workspace://SpacesStore/866c3275-531c-4823-8ad2-14f2a622baac#13)
What am I doing wrong?
Thank you.
Ales

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2009 10:48 AM
you need to wrap your Java code into an Alfresco "action" bean that you can then call from the JavaScript code via the "actions" object - that is exactly what the other user above did to get it working.
Cheers,
Kev

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2009 10:24 AM
Yes, it is javascript and I got your point.
So I try to follow this http://wiki.alfresco.com/wiki/Custom_Actions and this http://www.ecmarchitect.com/images/articles/alfresco-actions/actions-article.pdf
But I don’t understand where should be placed the code with class definitions. Maybe I am missing some basic knowledge…
Could you please write some short step-by-step procedure like for idiots?
Thanks a lot
Ales
