calling command line .exe from processing

I want to use a command line .exe to scan in a image to a file and then load the file with loadImage Using 2.2 so launch is not available tryed Process p= Runtime.getRuntime().exec(scanstr); but get IOException error

Can someone help with the right syntax please? command line is "c:\acquire.exe /SCAN" open("c:\acquire.exe /SCAN") works, but processing program goes on without waiting for process to finish This causes error because file is not there when loadImage trys to access it.

Any suggestions?

Answers

  • Processing has no way of knowing when the image is done scanning. You're going to have to add a delay yourself, or maybe a button that you push when the image is done scanning.

    I suppose you could check whether the file exists using Java code. Googling "Java check if file exists" is a good place to start, but the basic syntax will look something like this:

    File file = new file("path/to/your/image.jpg");
    if(file.exists()){
       //do something
    }
    

    You might wrap that in a loop that keeps looking for the file, or just check again every X seconds, depending on exactly what you want to do.

  • OK , i put a delay after the open call to the scanning .exe If finishes and when i try to load the image i get

    Uncaught error fetching image: java.lang.ArrayIndexOutOfBoundsExeception at sun.awt.image.PNGFilterInputStream.read(UnknownSource) at java.util.zip.InflaterInputDtream.fil(Unknown Source) on and on , a whole list of descriptions and then another Uncaught error and more descriptions

    The image sometimes appears correctly after words in the display, other times the top is cut off, but the program is still running and I can scan again from within the program. I have increased the delay to way past the scanning time and it still does this.

    The delay is right after the open statement that starts the command line .exe that scans the image. There is plenty of time in the delay if it actually stops the program at that point and waits. Is it possible that after the open call the delay is not seen or something weird? If it all happens in sequence the program should just wait for the scanned file to be written to disk and go on after the delay and it should work!

    I'm stumped, been playing with it for days. thks for any help or suggestions.

  • Please post your updated code as an MCVE.

    Keep in mind that scanning is actually several steps: physically scanning the image, combining it in memory, outputting to file, etc. It sounds like maybe the physical part is done, but the software hasn't finished outputting the data to a file yet.

    This is especially true if you're opening the file as soon as it exists. It could be that the file exists but is still being written to.

Sign In or Register to comment.