Skip to main content
Known Participant
September 13, 2009
Question

Coldfusion Jrun accessing server Clipboard

  • September 13, 2009
  • 1 reply
  • 708 views

Ok.  I have a java class that outputs the system clipboard.  so if you copy text on your server with a ctrl c, it saves it to the clipboard.  when I run the class via command line it is getting this text, however, when coldfusion calls this same class it sees the clipboard as being null. any idea what I can do to debug this?

I know his is vague, so if you have any questions shoot away.

my java class is as follows:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.datatransfer.Clipboard;
import java.awt.event.KeyEvent;
import java.awt.datatransfer.*;
import java.io.IOException;
import java.awt.Image;
import javax.imageio.*;


public class ScreenCapture2 {


public static void main(String[] args)  {
runit();
}

public static void runit()  {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
System.out.println(getClipboardData());
}    

public static String getClipboardData() {
        String clipboardText;
        Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);

        try {
            if (trans != null
                    && trans.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                clipboardText = (String) trans
                        .getTransferData(DataFlavor.stringFlavor);
                return clipboardText;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

coldfusion meanwhile calls a batch file that executes this class.

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
September 13, 2009

What happens when you send the output to file, like this

<cfexecute name="java" arguments="-classpath c:\javaProjects\test\ScreenCapture2" outputFile="C:\javaProjects\test\clipboard.txt" />