I'm writing a program that uses scp to copy files in a bigger java program. As it stands now, the program freezes up while the scp is copying the file, which can take a few minutes, so I'd like to be able to display the progress of the scp or at the very least get the terminal window with the scp progress to show up! Any suggestions?
scp writes to STDOUT and flushes the output. If you pipe the output, you may be able to read the output from the pipe, but my guess is that 1) scp wont print the progress bar to a pipe or 2) if you can do 1, the output will only make sense if you re-implement a pty or similar in a java window.
However, you could experiment with an expect-like module calling scp and mimic how the terminal works and you may be able to fake scp into thinking its being run as a terminal.
Finally, (and this is probably the best answer), don't use scp, find a java library to import that directly links into openssh's protocols for transferring files with scp.
When you say, "the program freezes up", my guess is that you mean that a Swing UI freezes up. If so, launch scp in a background thread and show the user an indeterminate progress bar.
Invoke the "launch scp" using SwingWorker to get it of the main thread and let the GUI update again.
To get actual progress you will need to investigate the characters printed by scp. I believe it maintains an ASCII progress bar, you can then replicate in Java. You may want to add "-v" to scp to let it be more talkative.
Related
I don't want my input/output to appear in the integrated Terminal, I want IntelliJ to open and use a new cmd.exe window each time I execute the program. Is that possible?
Edit: For clarification, since apparently I was using wrong terminology (sorry about that): By 'integrated terminal' I meant the 'Run' window (where all the System.out.print stuff goes).
So basically I want my program's output to not be shown inside this Run window, but rather inside a new terminal window (cmd.exe preferably), just like if you would start your programs from the terminal itself.
Is that still possible? Because I think it was at one point in the past. And if not, why?
I am writing a simple program in Java, and sometimes it randomly freezes and does not respond. when I try to end it with Ctrl-C instead of quitting, the program springs back to life and starts working fine again. I am not posting my code because I have noticed this behavior with other command line programs on Windows, so it does not appear to be anything specific to my code. The program will eventually be running 24/7 on a headless server, so you can see why it would be a serious issue if it just stopped working every now and then. Thanks in advance. Any help is appreciated.
This sounds a bit like perhaps a selection issue: If you make a selection in the console window, it freezes console output. The next time an application attempts to flush to the console it will stall until the selection is cleared. Pressing ctrl-c will copy the selection and clear it, allowing the flush to complete and the application to continue to run. Any keypress in the console window should clear the selection though, and it sounds like only ctrl-c is working for you.
If that's not what the issue is, your next best bet the next time you see this would be to open up a native debugger (e.g. Windbg) or a java debugger and attach to the process you're running in the console process to see what is doing the waiting. It's likely that something you're calling is triggering a spurious getch / readline / etc. A debugger should make the source of the stall obvious. If you need help deciphering the stack once you have one, I might be able to help. Just paste it into this thread.
Ben
I am running a Java process with several threads from a Powershell on Windows Server in Admin Mode.
Sometimes it randomly freezes until I press Ctrl+C, then it just picks up the work again.
Has anyone ever come across this problem and point me to where to look at?
If you start the process with Runtime.exec(..), it is sometimes necessary to read Bytes from the Process.getInputStream() resp. Process.getErrorStream(), else the process blocks, when it tries to write more to std-out (or std-err) than a certain buffer size.
I had this problem often, when starting Shell scripts.
You can create a Background Thread to read periodically from these streams.
Alternatively and more easy, you can use the ProcessBuilder class to start the shell process and use "inheritIO()" method.
I've a closed-sourced Windows XP GUI-based that performs some measurements.
My current manual workflow is:
Start the data capture by clicking on the "Run" button on the GUI
Stop the data capture by pressing the "Stop" button on the GUI.
Read some value displayed on the screen.
Save the data for the session to a file.
There is no library or API to automate this whole interaction and therefore I've no option but to do it manually :( and I'm sick of it !
As you clearly see that this approach is not only time-consuming but also error prone because it is limited by my reaction time which varies with every run.
I was wondering if there is a way to automate this interaction? If yes, what are my options? I would prefer to implement something in Python or Java. But I'm open to other options as well.
My idea is to implement a server process that runs on the Windows XP machine. I can then remotely send requests to this server process which in turn will execute my workflow automatically.
There's an amazing windows GUI automation tool called autoit. http://www.autoitscript.com/site/autoit/
You asked about linking AutoIt with Java. For my purposes, I've done this using a ProcessBuilder to create a Process, then get the Processes InputStream and ErrorStream and be sure to handle these streams in a separate thread. I have AutoIt communicate with my Java program using the InputStream. A good article for this (though a little out of date) is this one: When Runtime.exec() won't. It is key to be sure that the process be run on a background thread and that the two streams be read in their own threads. If you're doing this in a Swing GUI, then extra care must be taken that all Swing calls be made on the main Swing event thread, the EDT.
I am creating a program using Java Sockets in which I capture the client desktop and send messaging to client. Its working properly but now I want to block Client applications like Notepad, MS-Word, etc.
How can I do this?
Thanks.
It is hard to do using pure java API.
I do not know what do you mean when you say "block". The easiest way is to check from time to time running processes and kill one named "notepad" by executing taskkill from java.
If you wish to achieve effect of inactivity of application, i.e. user sees the notepad but cannot type you can do the following.
You have to check which application is on front. There is no clean pure java solution for this but you can probably write VBScript or JScript that does this task and run it from java. Once you detected that notepad is on top create transparent window (or even probably half-transparent window) that occupies full screen. Bring it on top. User will not be able to type into notepad because your window is on top but will see it.
Here is reference how to create transparent windows: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
Good luck.