Need to convert my Runnable JAR file into a batch file? - batch-file

I have a working Jar file. It is a Web automation where when I run the code some steps are happening over a URL. (which include pressing of few buttons also).
Now I want this to run when my machine is off. For that i need to schedule a windows job in task scheduler. Is it possible to convert my runnable jar into a batch file and then add a job in scheduler an do the steps when i am offline?
My code looks like this:
System.setProperty("webdriver.ie.driver", "C:\\Users\\x201691\\eclipse-workspace\\Mt_CacheFlush\\exefiles\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver(); driver.get("abc.com");
driver.findElement(By.id("overridelink")).click();
driver.findElement(By.name("password")).sendKeys("abc");
driver.findElement(By.xpath("//input[#value='Login']")).click();
driver.findElement(By.xpath("//div[#class='textMainNav' and normalize-space()='Overview']")).click();
System.out.println(driver.getTitle());

I can't make sense of "convert" a JAR into a batch file. There's no automatic conversion between the two.
If you only want to launch the JAR file from a batch file, you can
path\to\particular\jre\java -jar path\to\archive.jar
From there, you can create a scheduled task (Task Scheduler) that invokes the batch file for whatever criteria you have. IDK if Windows can actually turn the computer on in order to run a task, but if it's already running, you can certainly have the script run whether you're logged in or not.

From what I know, I don't think it's possible to convert a a JAR file into a Batch file. However, if you are insistent on running the JAR file from some form of Batch, you can create an extremely small batch file that will run the JAR file for you, that looks like this:
:start
START C:\<path-to-jar-file>
EXIT
Now, you can go into the task scheduler, and create a task that starts this batch file, then closes itself. I hope this helps!

Related

Creating a scheduled task for different users and battery mode off

I've a python executable file that I've written. I would like to distribute it to other people. The exe will be on the fileserver and this exe file should work on 14:00 for all the users.
Firstly, I tried to put it into a batch file with the cmd code to create a scheduled task and -schtask command-. The code is getting the directory into a variable and adding /program.exe and sending it to schtask command.
Problem is I can not set the option for working on battery mode in task scheduler with cmd.
Is there an alternative to CMD? As I understand, I can use powershell, but not sure how?
Thanks in advance.

background process launched by TFS is killed when switching to next step

I have some trouble keeping alive a background process when launched by TFS.
Usually I use a batch that launch a java server (new window), as long as I keep this window open it works properly.
C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\server.bat
In order to make my process automatic, I include this in TFS. In the step I call a batch that contains the following:
cd C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk // necessary to find the batch
start C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\server.bat
In my task manager, I can see in background tasks that java is launched (no new window is opened), exactly as it behaves when launching directly the batch. But after a few seconds, when TFS switches to the next step, it stops.
Then the next step carries on but fails as it requires the server to be launched.
Is there a particular way of doing it in TFS ?
thank you
Alexandre
It's suggest to launch the .bat file from a relative path not directly use cd to hard code the path.
Also recommend you to use Run Batch File task not Run Command Line task to launch the .bat file.
According to your description, seems you are using a run command line task in your build pipeline. Then run the command under the working directory c:\Build_work\5\s, the command cd to C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\ on the build agent, find the server.bat, run the server.bat.
First check if the .bat file is located at the path you are specifying on the build agent. Not sure if the bat file have to run under C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\, guess you are also hard code the path in your server.bat file. Suggest you change all the path to relative path, you could use some built-in variable in TFS.
As for your workaround in comment, seems you want to chain builds in TFS. The official docs literally say "not yet" and have a uservoice in planed. However you could use some workaround, such as create or use other's customize extension (use rest api) to call another build. Detail ways please refer huserben's answer in this question: How to chain builds in TFS 2015?
Note sure you have to go deep into this area for your original issue. Just add some related info in case you are interested or need.
Well,
Just in case someone else goes through the same kind of issue, I found a workaround:
I wish to mix different command line steps, some of them launching Python scripts:
I have one step for launching the server that is required for my testing tool, one step for my testing tool and one Python step for differential testing
I realized that I could embed everything in a Python script.
It can handle server launching process in a separate window (with subprocess), launch my Python part and launch another process for my validation tool.
I have to test the whole chain but, at least, I solved my problem of launching a background process and detach it from TFS

Batch File not starting automatically as a service

i am having trouble while starting a batch file as a service. the batch file runs fine when started manually but it doesnt starts a service and no ouput is observed. i have used nssm service manager to start the service.
below are the commands which i have used :
D:\nssm-2.24\win32>nssm install call
D:\nssm-2.24\win32>nssm start call
while installing i have provided the path of batch file.
the batch file contains the windows script to start few programs automatically.
you cannot just install any old executable as a service, and certainly not a batch file. a service is a program with a specific API which makes it react to service manager calls. ignore that, i just read up on nssm. still, there are probably better ways.
your use case sound rather like you might want to put your batch file in the autostart startmenu folder, to run it at login/startup.
or a scheduled task, if you want to restart it regularly.
one thing to consider, too, is the user under which the script is executed.

making .exe from .bat file tools and solution with dependencies

I have got a solution that uses a .bat file to start. I need to make it a .exe. I have used different tools like [BATch to EXE], [Bat_to_exe_converter], Bat to Exe Converter from [f2ko] which was the most modern one. I need help on the last one which is more sensible to work. or any other solution that makes a working .exe file. Right now, after converting the file to exe according to dependencies the start-up process will not complete. I should mention that the bat file is the Pentaho start-up file.
I have also used IEXPRESS from windows but the error after running the result exe is:
"Error creating process . Reason: The system cannot find the file specified."
Thanks,
Sounds like you need Carte. Carte is a web service that allows remote execution of jobs and transforms.
Carte User Doumentation
You'll probably also need to see this:
Carte as a Windows Service

Automate cygwin via batch file

Long story short... we have multiple servers which we run perflog monitoring on every night. My job is to convert these logs to .csv format and send them to my e-mail.
This bit it already automated via a .sh script an ex-employee wrote.
What I want automated is to run a batch job after the perfmon logging to look at a specific folder and find the latest .blg file and run the sh script on it (the script is called upload) so that I don't have to log in to each server and do it manually.
e.g.
upload myInitials cd /cygdrive/someLocation/logs/$latestFile$.blg
myInitials and the location can be hard-coded... I just wouldn't know how to find the latest file in the folder and automate it all via a batch file.
Any pointers would be very helpful!
# Jeremy:
Sorry, I probably should have mentioned in my question that the servers are running 2003 and 2008.
I don't think it would be absolutely necessary to register a change notification on the folder - If the log runs from noon till 7 in the morning, the script will run immediately after (you can set a script to run after a perfmon log has finished in log properties) so the log will almost definitely be the latest file in the folder anyway.
Like I said, I already have a .sh file in place to convert to csv and send to my e-mail, I just need to incorporate it into a batch file so that instead of me going to each of the servers and opening up cygwin and typing upload xx /cygdrive/location/logs/xyz.blg, I can have it automated to run straight after the log has finished without me having to RDC into it.
Thanks for the input!
If you have a Shell script and you job is to call the shell script from a windows batch file then this will work.This assumes the cygwin is installed in C:
Contents of start_cyg.bat
#echo off
set PATH=%PATH%:"C:\Cygwin\bin"
rem bash --login -i
bash "/cygdrive/d/cyg.sh"
Contents of cyg.sh
#!/bin/bash
TAIL=`ls -lrt | tail -1`
echo "TAIL:$TAIL"
If you call start_cyg.bat from windows command prompt you can get the output of the cyg.sh in the console
for getting newest file in a directory, ls -1tr | tail -1 should work.
First, I don't know if it would meet your requirements, but the Windows Task Scheduler 2 in Vista+ is very robust and can trigger an event even based on log entries. However, extraction and parsing of that log entry may require some scripting, and might have concurrency issues, even if that log entry did indicate the last used process. Chances are none of this is helpful, but just throwing it out there.
Programatically, it would be simple as you can register a change notification on a folder. When a change occurs, you go find the latest file. Then launch the batch file to launch your shell script, or whatever your desired sequence may be.
I think cygwin may even support change notification events via scripting, though I'm unsure. I believe there are linux extensions for this, but I may be wrong.
If it were me, I'd just write a little C++ app to do whatever I wanted.. but for you maybe any (or more likely none) of the above helps ;o.

Resources