简体   繁体   中英

Run Java utility from bat file or Jupyter Notebook

Trying to script out some download utilities from Domo. They provide a CLI int he form of a jar file. I can work it fine from the utility, but I am trying to script it to just run on a schedule. It works fine to load the jar file, but can't get the subsequent commands to run like they would when you just run it interactive from CMD.

java -jar C:\domo\java\domoUtil.jar 
&& 
connect -s yourdomain.domo.com -t mytokenhere
&&
query-data -i datasetid -sql "SELECT * FROM `hs_users_raw`" -xf test3.csv

Help would be appreciated, new to java, so not sure why I can't seem to get this working..

It appears that problem you are trying to solve here is to run some scripted Domo commands via the Domo CLI.

The way to do it is to put the commands that you want to run into a script file, then use the -script option to run it.

For example, put the following into a file called /path/to/myscript.domo .

connect -s yourdomain.domo.com -t mytokenhere
query-data -i datasetid -sql "SELECT * FROM `hs_users_raw`" -xf test3.csv

Then use domoUtil.jar to run the script as follows:

java -jar domoUtil.jar -script /path/to/myscript.domo

This is explained in the documentation for the CLI tool.


The reason that your current approach doesn't work is that && doesn't do what you want. In fact.

A && B && C

tells the shell to do the following:

  1. run shell command A
  2. if A returns a zero return code, run shell command B
  3. if B returns a zero return code, run shell command C

That doesn't work for you because connect and query-data are not shell commands. Rather they are commands for the CLI to run. Furthermore, you don't want to wait for the CLI to return a return code (ie complete) before issuing the connect and query-data commands to it.

The Domo CLI (probably) expects to read the commands from its standard input. Therefore, the following might work as an alternative (using a Linux shell):

java -jar domoUtil.jar <<EOF
connect -s yourdomain.domo.com -t mytokenhere
query-data -i datasetid -sql "SELECT * FROM `hs_users_raw`" -xf test3.csv
EOF

There is probably an equivalent using Windows batch scripting language.

Either way, the -script approach is what the Domo manual recommends.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM