aspose file tools*
The moose likes Java in General and the fly likes perl script sending signals to java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "perl script sending signals to java" Watch "perl script sending signals to java" New topic
Author

perl script sending signals to java

mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
Hello,

I have a perl program writing to a flat file and a java file reading from it. At some point of time the perl program should send a signal to the java program and the java on reading it should perform certain action on the flat file.

Could you please suggest how is that possible.

Mayank.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hmm, I'm no Perl guru but can't you just get perl to execute 'java <arguments> <program>' on the 'command line'?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
I dont want to execute the java program from perl. i want to send a signal from perl to an already running java app. The java app has to do some signal handling and take action according to that. Is it possible?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Again, I'm not sure of the 'Perl interacting with Java' capabilities, but is there a common protocol they can talk over? e.g. RMI? Web Services? Heck even get Perl to Touch a File and the Java program has a thread which detects the file time stamp changing?
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
Touching a File option i have tried and it doesnt fir my requirements. Do you have any idea about handling signals in java?
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
Could you please let me know something about how to handle signals in java and if perl signals can be handled as well. I tried searching but couldnt get much information. Could you please provide some pointers.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

mayank gupta wrote:Could you please let me know something about how to handle signals in java and if perl signals can be handled as well. I tried searching but couldnt get much information. Could you please provide some pointers.


You can't handle signals in 100% Java; the standard libraries have no signal-related capabilities at all. You might be able to use native code to handle signals, especially if you write main() in C and create a JVM from your C code. Even there, though, the JVM library does some signal handling itself (mostly just crash-protection) and your added handlers may either break things or not work properly.

Instead of using signals, let the Java program create a ServerSocket to listen on a well-known port; create a Thread dedicated to listening on that socket, in a loop. Then let that thread handle a simple command language. It's a simple matter, then, for your Perl program to connect to that socket and send the desired command(s).


[Jess in Action][AskingGoodQuestions]
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
Thank you for the suggestion. Is there any other way in which I can let the java program be informed when another program(perl) is renaming a file. I am not too sure about socket programming in java so it would be really nice if we could come up with something else.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Well you can have a thread or say a quartz driven timer to simply check the name of the file every x seconds.
mayank gupta
Ranch Hand

Joined: Dec 21, 2008
Posts: 78
I used the non standard API for the time being (to handle the signals) rather than going through the pain of the Native code.

Thank You.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: perl script sending signals to java