How to exec .pl files which is in a jar package?
hi,
i'm new to java so hope all the experts could give me a hand on this. i've a package structure as shown below. as you can see the a.pl file is in the lib folder which will be packaged in A.jar. so how am i able to call to execute the a.pl script if the java program (A.jar) being distributed? thanks in advance for the responds.
A.jar
=========
-src
---main.java
---utils.java
-lib
---a.pl
---b.vbs
Sorry i'm abit dump to java...Do you have a sample on
what you trying to tell me?i just not quite
understand if i getResourceAsStream is returned as
Stream then how can i pass over to a process the
arguments? thanks for the advice.Don't feel a 'dump'. This is not a trivial problem though the resultant code is quite small.
As long as you just want to supply input from the command line then this is my standard example of how you use a perl script from the jar or class path.
import java.io.*;
public class InlinePerlExecution
public static void main(String[] args) throws Exception
final String[] command = {
"perl",
"-", // '-' says take the script from stdin
"/home/sabre/jlib", // is the command line argument for the script
final Process process = Runtime.getRuntime().exec(command);
new Thread(new AsyncPipe(process.getErrorStream(), System.err)).start();
new Thread(new AsyncPipe(process.getInputStream(), System.out)).start();
// The perl stdin to write the perl script to
final OutputStream os = process.getOutputStream();
// The source of the perl script - at the root of the jar or on the class path
final InputStream is = InlinePerlExecution.class.getResourceAsStream("/wc.pl");
// Copy the perl script to perl stdin
new AsyncPipe(is, os).run();
is.close();
os.close();
final int returnCode = process.waitFor();
System.out.println("Return code = " + returnCode);
}You will need this utility class.
import java.io.InputStream;
import java.io.OutputStream;
public class AsyncPipe implements Runnable
public AsyncPipe(InputStream istrm, OutputStream ostrm)
istrm_ = istrm;
ostrm_= ostrm;
public void run()
try
final byte[] buffer = new byte[1024];
for (int length = 0; (length = istrm_.read(buffer)) != -1; )
ostrm_.write(buffer, 0, length);
} catch (Exception e)
e.printStackTrace();
private final OutputStream ostrm_;
private final InputStream istrm_;
}
Similar Messages
-
How to upload a file which may contain text as well as image to the server using windows phone 8 application ?
You're going to need to give way more detail about the situation before we can help.
-
How to point to the HelpSet file which is inside a Jar
Hi All,
Can anyone please help me out on as to how I incorporate my help files (which are inside a jar) with JavaHelp. They are working fine when they are in a folder. But giving an error when i am trying to reference it from a jar file.
Thanx in advance,
Debopam.Hello,
I have a little Example, and I hope this will help you.
Melly
* Opens the documentation in an JavaHelpViewer.
protected void showDocumentation() {
String jarFilePath = ".../test.jar";
HelpSet hs = getHelpSet(jarFilePath);
if (hs!= null) {
HelpBroker hb = new HelpBroker(hs);
hb.setDisplayed(true);
else {
System.out.error("Can't find the helpSet-file.");
* Returns the HelpSet file which is in included into the given
* jar file.
* @param jarFilePath
* @return the HelpSet file, or null, if the HelpSet file is not found.
protected HelpSet getHelpSet(String jarFilePath) {
HelpSet hs = null;
try {
String hsName = null;
JarFile jar = new JarFile(jarFilePath);
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String entryName = entry.getName();
if (entryName.endsWith(".hs")) {
hsName = entryName;
break;
URL url[] = getURLs("file:" + jarFilePath);
ClassLoader cl = new URLClassLoader(url);
URL hsUrl = HelpSet.findHelpSet(cl, hsName);
hs = new HelpSet(cl, hsUrl);
catch (Exception exc) {
System.out.error("Can't find a HelpSet file in: " +jarFilePath");
hs = null;
return hs; -
How to open my file which is in my c directory
hi
how to open my file which is in my c directory
for example i have one folder called "man" which is in my c directory,
is there possible to open that folder using sql query,if means please tell mehi
how to open my file which is in my c directory
for example i have one folder called "man" which is
s in my c directory,
is there possible to open that folder using sql
l query,if means please tell meWell, you can use the UTL_FILE package as described above, within PL/SQL, but if you want to access a file though an SQL query (as you stated) then you'd have to look into creating an external datasource and using SQL syntax such as...
select whatever
from table@ext_datasource_name
What exactly are you trying to achieve? -
How to upload a file which has more than 999 line item through BDC ?
Hello Techards
Hi to all
Can any body tell me how to upload a file which has more than 999 line item through BDC for traction F-02 ?
Thanks in advance.
ShovanHello Shovan,
You split it up to post two accounting documents with the help of a "suspense" a/c.
Say, you have to post the following line items below:
line 1 - dr. - GL a/c X - $1000
line 2 - cr. - GL a/c Y - $1
line 3 - cr. - GL a/c Y - $1
line 1001 - cr. - GL a/c Y - $1
You cannot post the above as a single doc in SAP (because of technical reasons), so you need to break it up into 2 documents as below:
Doc1
line 1 - dr - GL a/c X - $1000
line 2 - cr - GL a/c Y - $1
line 3 - cr - GL a/c Y - $1
line 998 - cr - GL a/c Y - $1
line 999 - cr - SUSPENSE a/c - $3
Doc2
line 1 - dr - SUSPENSE a/c - $3
line 2 - cr - GL a/c Y - $3
Note that there is no incorrect impact on accounting as first we credit suspense a/c by $3 and next we debit the same suspense a/c by $3 as a result the effect is nil. Similarly, we credit $997 to GL a/c Y (which is less by $3) in the first doc which is compensated by the second doc by crediting the shortfall of $3.
Hope this helps,
Cheers,
Sougata. -
In tiger, how do i list files which are open by some application.
In tiger, how do i list files which are open by some application without using "lsof" command.
Thanks,
But i m looking for the function to list the files opened by some application.
As i want to check whether a file is opened or not by some application. -
How to read a file which content hindi characters.....
I m reading a text file which content hindi characters.... but m nt getting the right result. It shows garbage instead of hindi characters.
plz somebody help me....:(You posted this in the XML forum. Is this an XML file you are asking about?
And we need definitions for some of the terms you used in your original post. You said "it shows garbage". We need to know:
1. What is the "it" there?
2. How does it "show" something?
3. What does the "garbage" look like.
In future you will find you get better answers if you write better questions. -
How to read a file which has header and without header
Hi,
I have a file to file scenario wherein there are txt files in the source system, some of which has header and some without header.
How does the sender adapter dynamically identify a file with header and without header.
I knew that File content Conversion in the sender adapter with "Recordsets per message = 1" can read the header. But how to handle dynamically.
Thanks in advance for suggestions and advice.
Regards.
PraveenHi,
Let me give a more clear picture:-
One of my file which has header and the corresponding values is listed hereunder:
PERNR;KID;PNALT;NACHN;NAME2;VORNA;TITEL;TITL2 and so on.....
;1200;1200;Angus;; and so on.........
Other file which has no header but only values in it:-
1200;1200;;Werner;Angus and so on.......
The structure remains same for all the files. The only difference is that some of the file has header in it and some without header. The Message Type is mentioned hereunder:-
DT_LegacyEmployee (Category - Complex Type)
Employees (Category - Element, Occurence - 1)
Employee (Categroy - Element, Type - DT_LegacyEmployee_Row, Occurence - 0...unbounded)
PERNR
KID
PNALT
NACHN
NAME2 and so on......
I read the file in record row. The file conversion parameters in the file sender adapter are mentioned hereunder:-
Document Name - MT_LegacyEmployee
Document Namespace - http://abc.com/xi
Recordset Name - Employees
Rescordset Structure - Employee,*
Recordsets per Message - 1
Key Field Type - String (Case Sensitive)
Employee.fieldSeparator - ;
Employee.endSeparator - 'nl'
Employee.fieldNames - PERNR,KID,PNALT,NACHN,NAME2,VORNA,TITEL,TITL2 and so on........
How do we dynamically identify whether the file has header or not. Even if the file has header or without header, the file needs to be picked and transferred to the target system. Kindly clarify.
Regards.
Praveen -
How to find LST file ,which is used in forms 6i
hi all,
can anyone tell me how to find the LST file in a form, i am calling one main LST file ,which fires when iwordpad pops up.. and when the wprdpad pops up ,it is saying that data not found in the data source ...
so wanted to check that LST file , in my form .
usually where ,in which trigger we will mention the LST file ... if anyone have this idea , please let me know .
cos in that LST file ,we will map the feilds which is used in both the wordpad and in my source tables.See http://www.experts-exchange.com/Databases/Oracle/Q_20060296.html for an example of ways to find & open a file.
-
Dear Sir,
I have recently purcased new mac pro but facing following problems, pls assist me:
1) I have downloded few application from iStore but this are in .ipa files and i dont know how to open this files
2) Which are good software for photo editing and business planners
3) where can i get detail information for handling the mac pro.
waiting for your reply,
Ramesh Satav
9890801841
Email : [email protected]1) A .ipa file is an app for IOS (iPhone, iPad..) and will NOT run on Mac OS X. Apps for your Mac can be found for example on the Mac App Store (you can find a link to it in the Apple menu on your menu bar).
2) I like Aperture and PixelMator
3) www.apple.com -
How to pen .boxchart file (which gives Firefox as default browser)
A friend has sent ma a .boxchart file, which I have downloaded. It gives Firefox as its default browser but only gibberish is displayed.
Something related to an ancestry.com application that you will need to install.
SEE: http://archiver.rootsweb.ancestry.com/th/read/MAC-REUNION/2007-10/1191285476 -
How to Read all files inside resource Folder inside Jar?
I have a Jar file,,,, The program reads for resource files in the resource folder inside the Jar. I want my program to read all files inside this folder without knowing the names or the number of files in the folder.
I am using this to make an Applet easy to be updated with spicific files. I just want to add a file inside the resource folder and Jar the program and automatically the program reads what ever is in there!!
I used the File class to get all file names inside the resource folder. it works fine before Jarring the program. After I jar I recieve a URI not Herarichy Exception!!
File fold=new java.io.File(getClass().getResource(folder).toURI());
String[] files=fold.list();
I hope the question is clear!!How to get the directory and jar file that you class resides in:
// returns path and jarfile (ex: /home/mydir/my.jar)
public String getJarfileName()
// Get the location of the jar file and the jar file name
java.net.URL outputURL = YourClass.class.getProtectionDomain().getCodeSource().getLocation();
String outputString = outputURL.toString();
String[] parseString;
int index1 = outputString.indexOf(":");
int index2 = outputString.lastIndexOf(":");
if (index1!=index2) // Windows/DOS uses C: naming convention
parseString = outputString.split("file:/");
else
parseString = outputString.split("file:");
String jarFilename = parseString[1];
return jarFilename;
}If your my.jar was in /home/mydir, it will store "/home/mydir/my.jar" in jarFilename.
note: getLocation returns "file:/C:/home/mydir/my.jar" for Windows/DOS and "file:/home/mydir/my.jar" for windows, thus why I look for the first and last index of the colon so I can correctly split the string.
If you want to grab a file in the jar file and get an InputStream, do the following:
import java.io.*;
import java.util.Enumeration;
// jar stuff
import java.util.jar.*;
import java.util.zip.ZipEntry;
public class Jaris
private JarFile jf;
public Jaris(String jarFilename) throws Exception
try
jf = new JarFile(jarFilename);
catch (Exception e)
jf=null;
throw(e);
public InputStream getInputStream(String matchString) throws Exception
ZipEntry ze=null;
try
Enumeration resources = jf.entries();
while ( resources.hasMoreElements() )
JarEntry je = (JarEntry) resources.nextElement();
// find a file that matches this string from anywhere in my jar file
if ( je.getName().matches(".*\\"+matchString) )
String filename=je.getName();
ze=jf.getEntry(filename);
catch (Exception e)
throw(e);
InputStream is = jf.getInputStream(ze);
return is;
// for testing the Jaris methods
public static void main(String[] args)
try
String jarFilename=getJarfileName();
Jaris jis = new Jaris(jarFilename); // this is the string we got from the other method listed above
InputStream is=jis.getInputStream("myfile.txt"); // can be used for xml, xsl, etc
catch (Exception e)
// this is just a test, so we'll ignore the exception
}Happy coding! :)
Doc -
How to create a file which i can attach to an email using the same print routine i use for printing
Hi all,
In my current code i print a document.
What I would like to do is attach this file - possibly as a pdf - to an email using the same print routine ( with some additional code obviously)
Did some research on the web and can't find a solution to this.
Any help would be appreciated.
Regards
Jan KonijnenbergWhat I would like to do is attach this file - possibly as a pdf - to an email using the same print routine ( with some additional code obviously)
You need to install a printer that 'prints' to a PDF file. Then send your document to that printer and attach the file. There are several available, free and commercial.
http://www.dopdf.com/
There are other formats which may be suitable.
http://www.howtogeek.com/150891/how-to-print-to-pdf-in-windows-4-tips-and-tricks/ -
How to read a file which as restricted access
Hi all.
Lets say I have two users User1 and User2
I have created a servlet which needs to read a file.
Lets say the owner of the file is User1.
So User2 cannot access this file.
This is on windows platform.
The problem is that the Servlet cannot know owner of its user.
Servlet run's as anonymous, so the user as to enter his userName and Password.
This is fine with me.
But after this how do I use this to read that file.
I have no clue on how to use this information to read this file.
Examples if any will be very helpful.
Thanks for your help in advance.Well, you'd hardly write a servlet that can access any file on your server, not exactly good security. Rather it needs to be confined to specific files or, at least, specific directories. The server can't change it's user identity, so it needs access to all files, but it's easy enough for the serlvet to have some mapping which tells it which files may be server to which users.
-
How to import CSV file which exists in specific directory
Hi,
There is one directory and new csv file is put there in daily batch. And the files have to be imported to DB.
I tried to use DBMS_LOB package, but it doesn't work.. So, if anybody know some good sample code, please tell me.If you are on 10g (not sure which exact release I'm afraid) you might look at Chris Poole's XUTL_FINDFILES that lists the files in a directory using PL/SQL and DBMS_BACKUP_RESTORE.SEARCHFILES (all a bit undocumented as it seems to be provided as part of rman).
Maybe you are looking for
-
PDF file getting corrupted while creating document
Dear experts , we are creating DMS document using BAPI_DOCUMENT_CREATE2 , its all working fine in DEV and Quality system but in production system in case of PDF file bapi is returning success message , but user is not able
-
External monitor issues with new OS
Since switching to the new OS Lion I can't get my external monitor to work through my Toshiba docking station. It used to work??
-
OAF in Oracle apps 11.5.8
Hi, Will OAF work in Oracle Apps 11.5.8. In the metalink i found JDeveloper for Oracle Apps 11.5.10. I am clear that we must download the correct version JDeveloper, But have a doubt that whether OAF pages can be done in Oracle Apps 11.5.8. Please he
-
Make large pdf starting from numbered pdf files
Hello, I have a weekly job I do In acrobat Pro but would like to do without acrobat. 1. I have a folder with pdf files numbered from 1 to ... For example 1.0041job1.pdf / 2.147job2.pdf / ... The number of pdf files changes every week depending severa
-
Gallery: read Metadata tags
Hello, LR-WEB-Gallery provides options to read metadata tags and insert them into WEB-pages by means of this code: ["perImageSetting.keywords"] = { enabled = true, value = "{{com.adobe.keywords}}", title = LOC "$$$/WPG/HTML/CSS/properties/Image