Interact with another process

Does anyone know how can I make my program send/read text from another program? Let's say that my active window is Notepad. I would like to be able to insert text and also read what has been typed (i.e. it would copy & paste).
Any macro program can do that, but I want to treat the data with Java.
Thanks.

If what you want is just a copy&paste tool wich can interact with other programs, you can try the api clipboard from awt:
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.Toolkit;
it can be useful:
// clipboard
public void getClipboardContents() throws Exception
     BufferedReader in;
     Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     Transferable contents = clipboard.getContents(null);
     boolean hasTransferableText =(contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
     if ( hasTransferableText )
          in = new BufferedReader (new StringReader((String)contents.getTransferData(DataFlavor.stringFlavor)));
          String linea = in.readLine();
          while (linea!=null)
               linea = in.readLine();
          in.close();
public void setClipboardContents( String aString )
     StringSelection stringSelection = new StringSelection( aString );
     Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     clipboard.setContents( stringSelection, this );
the clipboard can be fullfilled from any app and read from java because it's a sysyem pool, but you cannot receive events from windows apps like notepad, you can copy notepad's text and paste it to your java app.

Similar Messages

  • Microsoft sql client deadlocked on lock resources with another process

    Hi
    I wrote a forecasting report for a customer which creates an excel spreadsheet with the information
    Depending on how they run the report it can take between 5 to 15 minutes to run
    We have just upgraded the customer to SAP 8.8 PL10 and Microsoft SQL Server 2008 and they seem to be getting an error -
    Microsoft sql client deadlocked on lock resources with another process .......
    The error seems intermittent, they may get the error once and the next time they run it, it is fine.
    I have never seen this error before and they never had it before on SAP 2005
    Can anyone suggest anything please?
    Thanks
    Regards Andy

    Hi Andy,
    I was having the same problem. I'm gonna tell you what i did.
    My query usually takes from 10 to 15 minutes to show results. That long time also block all transaction in the database.
    I was reading about some techniques to improve queries performance. Some of the tips are:
    1. Review indexes in the table you are querying
    2. Use Views
    3. Avoid cursors
    4. Archive old data
    5. Use the correct transaction isolation level
    The last one, was the tip that helped me to avoid the block in the database.
    By default the isolation level in SQL Server is Read Commited, that explains why the database block some transactions. For example, if you have a query that take data from JDT1 table and it takes several minutes to show the results, other transactions that try to write in the same table should be blocked if they arrive at the same time of the first query.
    To solve this, you can make your query in a transaction with Snapshot isolation level. It means that your select query will take a snapshot of the data without blocking any other transaction.
    Here is an example how you can make it. The difference is that you may use ADO.NET connection replacing DI API Connection:
    oConnection = OK1.Generic.Helpers.setConnection(server, password, userID, db); // You have to set anyway your sqlconnection
                        if (oConnection.State == ConnectionState.Open)
                            oCommand = new SqlCommand();
                            oCommand.Connection = oConnection;
                            oCommand.CommandTimeout = System.Convert.ToInt32(timeOut);
                            oCommand.CommandText = "ALTER DATABASE " + db + " SET ALLOW_SNAPSHOT_ISOLATION ON";
                            oCommand.ExecuteNonQuery();
                            sqlTran1 = oConnection.BeginTransaction(IsolationLevel.Snapshot);
                            oCommand.CommandText = query;
                            oCommand.Transaction = sqlTran1;
                            oCommand.ExecuteNonQuery();
                            sqlTran1.Commit();
                            oCommand.CommandText = "ALTER DATABASE " + db + " SET ALLOW_SNAPSHOT_ISOLATION OFF";
                            oCommand.ExecuteNonQuery();
                            if (oConnection.State == ConnectionState.Open)
                                oConnection.Close();
    In this example I write the data to show in the report in other table, then the report takes the data from that table.
    I hope it will be helpful for you.
    Regards,
    Juan Camilo

  • Interacting with external processes

    What are the options in the latest AIR regarding interacting with external processes running on the same machine?
    Thanks

    You will need to user AIR 2.0.
    Here is a tutorial:
    http://www.adobe.com/devnet/air/ajax/quickstart/interacting_with_native_process_print.html

  • Interaction with another applications

    Hi:
    I would like to know if exists any posibility of communicate
    or interact my flash app with another non-flash application (for
    example using JNI or any kind of median layer between my flash app
    and another app).
    Thanks

    Hi there,
    Yes it is possible. You can use FSCommand("launch") to do
    this.
    ///example:
    The following example would open wap.yahoo.com on the
    services/Web browser on Series 60 phones:
    on(keyPress "9") {
    status = fscommand("launch",
    "z:\\system\\apps\\browser\\browser.app,
    http://wap.yahoo.com");
    Hope this helps,

  • Interact with extern process by Runtime.exec()

    Hi,
    I want interact with a extern process by Runtime.exec(), but I don't Know the way for introduce the params required for the extern process.
    So, Is posible, interact with the extern process from Java?
    Thanks

    Exactly, I would like to know how exec can pass a PIN
    number when the proccess already has been launched. Sounds like you're doing it through the process' stdin. Read that article I linked.
    You'll have to call Process.getOutputStream() or whatever that method is. To you it's an OutputStream, to the process, it's input. You'll write the stuff to that stream that you'd type to the command line. If you want to get that from the user interactively, you'll do it like you would any interactive user input in any Java program--get it by reading System.in or from some GUI element, and then take that and write it to the process' stream.
    If you're not familiar with I/O in Java, look here:
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Knowing with another process has finished writing to file

    Hi,
    We have the following situation:
    - Some (non-java) process is uploading files to some directory.
    files are huge (several Giga), and size is not known in advance.
    - We need java to monitor this directory, and tell when a file has finished uploading (so the entire file is ready on disk).
    Is there a way to do it ?
    Some things I've tried , that didn't work:
    - Checking File.canWrite() (hoped that if another process is writing to file, java would get canWrite=false). No luck.
    - Opening a FileInputStream (or nio's FileChannel) and waiting for EOF. No luck either (if the other process has written, say, 1/2 the file, then java would read half the file and then report EOF, even though the other process hasn't finished writing).
    Any ideas would be appreciated (even if anyone knows of a platform-dependent solution, e.g one that only works on Windows or Unix, it would still help).
    Thanks very much.

    Well, going to platform specific solutions, there's probably some way on *NIX to see if a file is open or not, you could go through Runtime.exec() to check for that.
    Of course that's not a very elegant solution, but Java has very limited tools for this sort of thing.
    Let's wait for a better solution...

  • How to use progressbar with another process ?

    Hi guys, i am working on an audio processing project in which i want to implement progressbar.I have two separate classes in which one contains code for GUI and another contains code for the logic when some event occurs in GUI.
    I have process button whose click event does the processing of files and attach tags to it.
    The processing of files does in another class. I have tried using the progressbar with GUI when user clicks process
    it should co-relate with appropriate message like "(Processing 1 of 10 files) " and side by side progress also been shown and when all tags attached to the files completed then it should give finished message on progressbar.
    public javax.swing.JProgressBar progressBar;
    public TAG{
    progressBar = new javax.swing.JProgressBar();
    progressBar.setName("progressBar");
    this.progressBar.setString("Awaiting User Input");
    this.progressBar.setStringPainted(true);
    private void processBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processBtnActionPerformed
            // TODO add your handling code here:
            AudioTagProcessor audioTagProcessor = new AudioTagProcessor();
            FileHelper fh=new FileHelper();
            int mp3Files = fh.getFiles(new File(sourceTxt.getText()), AVLConstants.FILE_TYPE_MP3);
            //setJProgressBar1(jProgressBar1);
            if(mp3Files>0){
                setProgressBarToDisplay(mp3Files);
                processBtn.setEnabled(false);
                timer.start();
                try{
                    FileUtils.copyDirectoryToDirectory(new File(sourceTxt.getText()), new File(destnTxt.getText()));
                   audioTagProcessor.searchForTags(new File(sourceTxt.getText()), new File(destnTxt.getText()), AVLConstants.FILE_TYPE_MP3, this,progressBar);
                    progressBar.setString("Finished Processing "+mp3Files+" of "+mp3Files+" files.");
                    addToActivityLog("Processed " + mp3Files + " files of " +AVLConstants.FILE_TYPE_MP3+ " type.");
                }catch(Exception ie){
                    ie.printStackTrace();
            }else{
                addToActivityLog("Selected 'Source Folder' does not contain any files of type " + AVLConstants.FILE_TYPE_MP3
                        + ". Please Selected a folder containing files of type "  + AVLConstants.FILE_TYPE_MP3);
            }The addToActivityLog is a text pane where i used to display message.
    The AudioTagProcessor is a class where i used to do tag attachment to mp3 file.
    The problem comes is that whn i click process button it completes all the tag attachment process and then the progressbar starts and displays message. Is there any way so that i can relate both the processes with each other like when tag is being attached side by side progressbar also increases and give me appropriate message.
    Can u plz help me how to do that ?

    DarrylBurke wrote:
    sureshot324 wrote:
    Yeah read the link. Basically how it works is you launch another thread that does the heavy work and updates a variable (usually an int, or define your own Progress class that includes a status message) that keeps track of the progress. You then launch a Timer that checks this variable at a certain interval, say every 200 miliseconds, and updates the progress bar accordingly.Looks like you're not familiar with the JDK 1.6 SwingWorker, with its doInBackground, publish and process methods :-)
    dbNope I'll have to look into it. Does it really make it much easier than my method though?

  • Interacting with perl through java.

    I'm trying to do something with Java that I haven't managed to do until now. I'm trying to interact with a perl process giving him input and reading output.
    I have a perl module that has several functions and the idea is to launch a process in a java program with the following line :
    perl -e 'while(<STDIN>) { eval $_ ; }'
    and then give the process the necessary input and the read the given output.
    For instance with the above line you can do the following:
    [user@host ~]$ perl -e 'while(<STDIN>) { eval $_ ; }'
    print "Hello World\n";
    Hello World
    Here is the code I'm using:
    import java.io.BufferedReader;
    public class ExecProgram {
    private static Runtime runtime;
    private static Process process;
    public static void main(String[] args) {
         runtime = Runtime.getRuntime();
         try {
         process = runtime.exec("/usr/bin/perl -e 'while(<STDIN>) { eval $_ ; }'");
              process = runtime.exec(cmd);
         } catch (IOException e) {
              System.err.println("Error executing process");
         PrintWriter out = new PrintWriter(process.getOutputStream());
         String commandLine = "print \"Hello World\n\"";
         out.println(commandLine);
         BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
         try {
         String line;
         while ((line = in.readLine()) != null)
              System.out.println("Output: "+line);
         } catch (IOException e) {
         System.err.println("Error reading output");
    As you can see I'm using Runtime class to interact with the process but nothing happens if replace the exec line with:
    process = runtime.exec("ls");
    I can see in the output the listing of the current directory.
    Have you ever tried something like this? Is this the correct way for doing this?

    Have you ever tried something like this? I have. Here's a rough sample:
        public static void main(String[] args) throws Exception {       
            String[] cmd = new String[]{
                "/usr/bin/perl",
                "-e",
                "while(<>){ eval or die $@; }"
            final Process p = Runtime.getRuntime().exec(cmd);
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        for(String line; (line = r.readLine()) != null; System.out.println("ProcessOUT:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                        for(String line; (line = r.readLine()) != null; System.err.println("ProcessERR:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        OutputStream out = p.getOutputStream();
                        for(int ii = 0; ii < commands.length; ii++){
                            System.err.println("Sending command: "+commands[ii]);
                            out.write(commands[ii].getBytes());
                            out.write('\n');
                            out.flush();
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            int exit = p.waitFor();
            System.err.println("Process exited with code: "+exit);
        static final String[]
            commands = {
                "print \"The road goes ever\\n\";",
                "print \"ever\\n\";",
                "print \"on.\\n\";",
                "exit 13;"
        ;

  • Interacting with processor

    Okay, so I'm curious about how to use Java to interact with the processor like you would with C or C++. For example, what if I wanted to interact with a process or write a software driver using Java.

    write a software driver using JavaYou can't.Well I fact you can, but not on all platforms, may be only one : see the JNode project
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                           

  • Muliple process interactions with client

    Is it possible to have multiple interactions with the client?
    I have a BPEL process that calls a web service and then replies to the user what is sent back. This is then used by the user to invoke another web service through the business process.
    In other words: the client initiates the process, the process uses this to invoke a service. The reply is sent to the user. The user then sends another message to the process which uses this to invoke another service. The result of the service invocation is sent to the user by the process.
    This seems really simple but I am having trouble achieving this and all examples seem to be one invocation by the client and then one repliy. If anyone knows if/how this can be achieved it would be greatly appreciated.
    thanks,
    Clive
    Edited by: clive jefferies on Dec 3, 2008 10:51 AM

    yes, its pretty much possible to call the same BPEL instance again and again. This is called Asynchronous call back, and is possible with WS-Addressing or you can use the BPEL Correlation set to achieve this functionality.
    Here is a step by step tutorial on how to achieve this,
    http://technology.amis.nl/blog/2813/use-bpel-correlation-sets-for-repeated-synchronous-access-to-long-running-bpel-processes
    Hope this will resolve your problem...
    -Abhi

  • The process cannot access the file because it is being used by another process with Execute package task

    Hi,
    I've a master package that calls other packages with an Execute Package Task. Sometimes we have an error: "The process cannot access the file because it is being used by another process" and sometimes not. It seems random.
    We are working on a Terminal Server and the SQL Server database engine and the files are placed on another server. It seems that the errors doesn't occu when we run the packages on the server with a job. We can't log onto the windows server on this machine..
    Hennie

    I've seen this myself. On most occasions an immediate rerun would fix the issue. As stated this happens only when we try to run this from BIDs. From SQL agent job it always runs fine. 
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Interaction Flash Lite  with another applications

    Hi:
    I would like to know if exists any posibility of communicate
    or interact my flash lite app with another non-flash application
    (for example using JNI or any kind of median layer between my flash
    app and another app). This non flash app may be a java app for
    example or another symbian app that I have developed
    Thanks

    Hi there,
    Yes it is possible. You can use FSCommand("launch") to do
    this.
    ///example:
    The following example would open wap.yahoo.com on the
    services/Web browser on Series 60 phones:
    on(keyPress "9") {
    status = fscommand("launch",
    "z:\\system\\apps\\browser\\browser.app,
    http://wap.yahoo.com");
    Hope this helps,

  • Interacting with a compiled LABView executable from another VI

    I'm using a piece of hardware that has it's driver executable written in LABView. I would like to interact with it from the inside of my own VI. There's no dedicated LABView driver and I don't have access to the source code. Communication happens over USB. The particular functionality that I need is changing one numeric control, which governs the current that's provided.
    Could someone help me with this in any way?
    If that matters, I'm using LV2013.

    Was the exe built with VI Server/ActiveX enabled? If so, all you need is a set control value method. If your company was the one that commissioned the exe, for a small cost the vendor can enable this option and rebuild it. If you did commission it, you should have required the source code in the contract.
    Other options include using something like AutoIT. You could also turn on NI-Spy/I/O Trace and capture all of the VISA commands. Even though there might not be a driver, you should have a manual that you can read. Implementing a single command should be pretty trivial.

  • Math Interface Toolkit in Matlab: Can I interact with a VI as a parallel process

    I'm curious if it's possible to create a Matlab MEX file using the LabVIEW Math Interface Toolkit (MIT) that can be called in matlab and accessed while running?
    I'd like it to effectively work just like any other object in matlab.  I'd like to be able to query the object while it's running, dump values out of a buffer, and even hook events if possible.
    As it currently stands, the VI to MEX setup seems to just allow me to call a VI, run it, and then drop out.  I want to be able to continuously acquire and access the data as it's coming in and interact with it from matlab (i.e. fully integrate the VI into my matlab code as a separate object).
    Is this possible in some form or am I stuck with dedicating the matlab interface to the VI whenever I want to call it?
    Thanks

    Hi GusLott,
    You are correct that when you call a VI the command line will not continue until the output is obtained.  This makes sense since in LabVIEW that is how a VI operates (a subVI does not ouput until all outputs are obtained).  I believe this is also how commands in MATLAB work as well (correct me if I am wrong).  On the otherhand this is not a disadvantage in labVIEW since you can run VIs in parallel.  If you can create some way to run parallel threads in MATLAB then you will be able to do two (or more) MEX calls at once. 
    As far as object oriented programming goes, there is a labVIEW OOP, but I do not think it has been tested in conjuction with the Math Interface Toolkit.
    Brian K.

  • Able to interact with a cRIO remote front panel from one computer but not another

    I have a cRIO application that publishes a remote front panel for monitoring and control of the application. From one PC (Win7 & firefox) I can see, interact and control the cRIO through the published remote front panel. From a second PC, also Win7, I can see and monitor the cRIO's state, but the remote panel that is opened does not allow for any interaction and this is true whether I'm using IE, FF or Chrome as the browser. When either PC is connected to the cRIO, it is via a dedicated Ethernet link and only the cRIO and the one PC are on that network. For this two-device private network, the PC is always at address 192.168.1.1 while the cRIO always uses 192.168.84.199 (port 8000).
    The firewall rules on both PCs are setup to allow all incoming and outgoing programs/ports/protocols to be used between these two IP addresses.
    Both PC's have up-to-date LabVIEW development systems installed on them (which more or less guarantees they have the minimum require LV runtime needed to see and use a remote front panel).
    What might be different on the PC that view but cannot interact with the remote panel?
    Solved!
    Go to Solution.

    Sam_Sharp wrote:
    Right click on the second one and select "take control of this VI".
    As far as I am aware - only one viewer of the remote front panel can control the panel at any time - the rest can only view.
    As I tried to say in my original post, there was only one host physically connected to the private network at any given time (by virtue of the fact that the one Ethernet cable connection to the private network was being moved back & forth between the two hosts) so there was no way both hosts could be trying to control the cRIO at the same time. I even went so far at one point of restarting the cRIO while it was connected to the problem host to see if would render it functional, but it did not.
    But I did not know that it was possible to do what you suggested, much less that there was a right-click context menu associated with a remote panel, so I tried it and it worked!    Thank you!

Maybe you are looking for

  • The custm error page is not getting loaded in TomCat 5.0

    Hi all, I am working on a JSF web application deployed in Tomcat 5.0.I was trying to redirect 404 and 500 error pages to custom error pages.But the error pages are not getting loaded and i am getting normal Tocat 404 status page. I am giving the web.

  • Updating JTable Column in real time

    Hello: I have a JTable which has listener listens for a specific event and updates the corresponding column accordingly in real time. This works fine. One small problems though, the user could actually see the redrawing of the JTable sometimes. Most

  • How to set iPhone Bluetooth to be just for phone calls?

    Is there a way to setup an iPhone 4s/5, iOS 6, to use the bluetooth only for phone calls? I don't want music, youtube, google maps, or any app to go thru my car speakers. Phone calls work fine because the car will switch to Bluetooth audio automatica

  • Email link will not open on desktop computer

    Hello. I am wanting to know why I can open email links from Shopify on my tablet and cell phone but not on my Desktop computer.  Thank you in advance for your help with this.

  • Windows 7 - jpg "open with" launches PSE11 but doesn't load photo.

    In Windows 7 explorer I can't just right click on a jpg file to open and then load the photo into Photoshop Elements 11. PSE11 loads properly but with an empty workspace. I then must do a file, browse, open, etc. to find my photo. This has resulted a