How to see sikuli logs during execution? - java

I'm trying to output some debug info in a Sikuli script using print but I can see this info only after the script has finished execution because the IDE hides itself while the script is running. Is there a way to see those logs during execution? Like outputting this info to console or (better) not hiding IDE during execution?

(1) You could use a pop-up:
popup("Hello World")
(2) You can use Jython's File IO
f = open("myLogfile.txt", 'a')
f.write("Log Message")
f.close()
Now if you open the log file in a text editor that warns about changes made to the file (ie NOT Notepad.exe), you can then see your print statements every time the file is appended by your script.

You cannot hide the IDE in background during script execution.
However,there's an alternative to view the logs.
You can install the package which launches your sikuli via command prompt(sikuli-script.jar),
refer to https://launchpad.net/raiman/+download
you won't need the IDE to launch your scripts this way.
Now after changing necessary environment settings you can type-in simple path like "java -jar %Sikuli_Home%\sikuli-script.jar -r %Sikuli_Scripts%\main.sikuli" in cmd and get started.
here 'main' is my driver script where I have imported my modules under single .sikuli folder (main.sikuli) you can have any file name like abc.sikuli
(here you need to store your path in a variable like ,path = os.environ['Sikuli_Scripts'])
Also ,it is a good practice to launch applications creating batch files and accessing files using relative path.

Related

How to run jlink-generated Java runtime image without CMD window?

I've created Java runtime image for a simple OpenJFX application. In order to run this app, jlink auto-generated two lauch scripts under %image_path%/bin directory. This how it looks like (the one for Windows):
#echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
"%DIR%\java" %JLINK_VM_OPTIONS% -m app/com.package.Launcher %*
Obviously, when I run this batch file it opens new shell window, which is not what I want to. I've tried all common approaches: use javaw instead of java, run script via start command etc. Nothing works.
Is it possible to avoid shell window or somehow create native launcher?
Ok, I've figured out it's not posiible to eliminite shell window completely. In the best scenario it's just flickers for ~1sec. This is how it can be achieved:
#echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
start "" "%DIR%\javaw" %JLINK_VM_OPTIONS% -m app/com.package.Launcher %* && exit 0
There is a feature request about native laucher implementation but it's not discussed actively.
Nonetheless I've solved the problem. There is "Batch to EXE Converter" tool. It can generate executable (basically the same batch file) which can run your app silently.
This looks to be possible using vbscript. If you put the following script into a .vbs file next to the launcher.bat file (or whatever the name of the batch file is):
CreateObject("Wscript.Shell").Run CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\launcher.bat " & WScript.Arguments(0) & " > " & CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\launch-log.log", 0, False
This runs the batch file in the same directory, and also redirects stdout to a log file.
What you´d like to achieve is very well possible. It is actually even quite easy and I use this every day. There already is an early access build of jpackage available here: http://jdk.java.net/jpackage/ Creating executables works already
nicely (I use it on Mac and Windows). Only creating installers is still a bit problematic.
It's very easy to run a bat file without showing the cmd window.
you just need to create VBS file to run bat file with the following cmd
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & ".\bin\launcher.bat" & Chr(34), 0
Set WshShell = Nothing
Save cmd in the file out of the bin folder with any name like
Launcher.vbs.

Write to console from a native javafx app created with Inno Setup and maven

I have a JavaFX app, and I am using the maven plugin javafx-maven-plugin to create an app bundle (app.exe in Windows, generated with Inno Setup).
The app runs in console mode when arguments are given.
The problem is that when running in console mode, I can't see the mesages printed to console. The messages (written with System.out.println) don't appear in the Windows console. But they are generated, because if I redirect the output to a file (app.exe > out.txt) the file contains all the messages.
I have tried to run the .exe with cygwin and even compiled the whole project in Linux, and in both of them the output is correctly displayed in the console. So the problem seems to be only when running the javafx exe with the Windows console (cmd). I guess the stdout is redirected to somewhere. How can I change this?
First of all: thanks for using the javafx-maven-plugin, I'm the maintainer of that maven-plugin.
short version: you can't do very much
long version:
The problem comes with the native launcher of the JDK and has nothing todo with InnoSetup, nor Maven.
Quoting the source-code itself this is what happens:
Basic approach:
- Launcher executable loads packager.dll/libpackager.dylib/libpackager.so and calls start_launcher below.
- Reads app/package.cfg or Info.plist or app/<appname>.cfg for application launch configuration
(package.cfg is property file).
- Load JVM with requested JVM settings (bundled client JVM if availble, server or installed JVM otherwise).
- Wait for JVM to exit and then exit from Main
- To debug application by set env variable (TODO) or pass "/Debug" option on command line.
- TODO: default directory is set to user's Documents and Settings.
- Application folder is added to the library path (so LoadLibrary()) works.
After digging a bit inside the launcher, if found the spot, where the STD-output is retrieved, which gets compiled, because on windows-systems "USE_JLI_LAUNCH" is not set. The real problem with this comes with the condition to only append that console-writer when being compiled with DEBUG-flag
It might be a bug/fluke within the JDK itself, I'll try to find something and might file that as bug on oracle-bug-tracker.
EDIT: after some further digging, there is something I found interesting: the generated EXE-file is a simple windows-executable, no cli-executable as seen in the launcher-source-code, that is the reason you dont see any console-output but having the result when pipelining into some file.
Workaround: create/compile your own native launcher-file using some redirects as described here:
Redirecting cout to a console in windows
https://bobobobo.wordpress.com/2009/03/01/how-to-attach-a-console-to-your-gui-app-in-c/

System command not working in Ruby and returning false?

I would like to run a Java program, which is a standalone application, from Ruby. I am using the following commands in Ruby:
system("cd /home/webserver/testproject");
system("sh testsh.sh")
My Java project is available in "/home/webserver/testproject", so I am changing the directory using the first command. The sh file writes a file which contains info to run my main class and also sets the CLASSPATH environment variable to run program. When doing this outside of Ruby it's working properly but not inside Ruby.
system makes a new subshell every time you run it, so you always start in the current directory. What you need is to change the directory inside Ruby with Dir.chdir:
Dir.chdir("/home/webserver/testproject") do
system "sh testsh.sh"
end
The change in the working directory will only be applied to the code inside the do … end block. If you want to make the change permanent for the whole script, you can do it this way:
Dir.chdir "/home/webserver/testproject"
system "sh testsh.sh"
Calling system("cd ... changes the current working directory only inside the scope of the command. To run the second command in the correct directory, you need to chain them:
system("cd /home/webserver/testproject && sh testsh.sh")

Execute a java program on login

I need to write a program which executes
whenever some one logged In to the windows system.
It is for daily report generation purpose.
I have written the program but couldn't get how to execute it on user login.
All the help would really be appreciated.
EDIT most of the people suggesting that I should put file in startup folder, but startup files only execute if 'system started/restarted'... I need to run the program whenever a user login like if the computer is started but locked and then someone unlocks, this program should be executed.
Correct me if I am wrong.
If you are working on a Windows OS then you can create an executable jar file of your java.
In order to make it launch at login you need to include it to the windows startup list.
You can create a batch file (.bat) in which you put:
"<YOUR PATH TO JAVA>/javaw" -jar "YourJar.jar"
Add this .bat file to windows startup check this
Batch/CMD: Adding files to Startup list
Hope it helps !
Setup your java application to run as a windows service.I think this answer will help you.
Answer is here
Create a batch program and put it on startup that should start your target file to run what you want to do.....
batch code :
start java target.java
Must setup the path for startup b4 run....
#happy Dev: hope you already know how to make a .bat in windows, just create a bat file which has line to execute java. or for more help on this you can see:
http://introcs.cs.princeton.edu/java/15inout/windows-cmd.html
Just make sure you have java installed on that machine. and your environment variable is set for java other wise you have to provide the complete java bin path.
Regarding how to run on login. simple way to go:
for windows 7: start menu--> All programs--> find a folder name startup and right click on it. there you can see open for all users open it and place your file there. every time when some user login the bat file will be executed automatically. and remember this wont work on hibernate. or to open that location you can just go to:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
for Other OS path is almost similar with just a minor difference.
You can use Task Scheduler for Windows Platform and configure which file to call at Login Time.
C:\Windows\system32\taskschd is the location.
Create a basic Task or Create Task...... are the options.!!
You can schedule the time of your task to get executed.

debug application by running .sh file using eclipse

I have a .sh file which runs independently on Linux server to sync some data but now there is some problem with the sync so I wanted to run this .sh file in debug mode in eclipse so that I can check my java code where the problem is?
Is there any plugin or options available in eclipse to do this.
Please let me know if you need any further information.
If you want to debug your java code which your shell script invokes, just write a wrapper java code which invokes your main java code, and you can easily debug using eclipse.
What is the content of this .sh file? Is it running a JAR?
If so, you can remotely debug a java code. The following blog explains using screenshots: http://javarevisited.blogspot.co.uk/2011/02/how-to-setup-remote-debugging-in.html
I don’t think we can use shell script debugger in the Java debugger session. i.e you need to debug java code and shell script code separately in separate debug sessions.
You can use basheclipse to debug shell script, this will only work with shell script editor ShellEd.
Also check the open tickets for debugging in ShellEd.
Note
Outside eclipse you can try http://bashdb.sourceforge.net/

Categories