- 1 year ago
Script to add to BAT file so output could show from a jar that sweeps web
If you want to run a Java .jar
file from a batch file and display the output in the console, you can use the java
command with the -jar
option and pipe the output to the console using the cmd
command. Here's an example:
batch@echo off
setlocal
set jarfile=mywebcrawler.jar
set url=http://www.example.com
set outputfile=output.txt
java -jar %jarfile% %url% > %outputfile% 2>&1 | cmd /q /v /c "more"
In this example, the script sets the jarfile
variable to the name of the Java .jar
file you want to run, the url
variable to the URL you want to crawl, and the outputfile
variable to the name of the file where you want to save the output.
The java
command is used to run the .jar
file with the specified URL, and the output is redirected to the outputfile
. The 2>&1
part of the command redirects the error output to the standard output so that it can also be piped to the console.
The more
command is used to display the output in the console. The /q
option turns off the prompt at the end of the output, the /v
option enables delayed environment variable expansion, and the /c
option runs the command specified in quotes.
You can modify this script to use your own .jar
file, URL, and output file. Note that the output file will be overwritten each time you run the script, so you may want to modify the script to append the output to the file instead.