英文:
Run Java utility from bat file or Jupyter Notebook
问题
尝试从Domo下载工具脚本。他们提供一个以jar文件形式的CLI。我可以从工具中正常运行它,但我想将其脚本化以便定时运行。加载jar文件没有问题,但无法像在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
需要帮助,对Java不太熟悉,不知道为什么无法让这个工作起来...
英文:
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..
答案1
得分: 0
这里你试图解决的问题是通过Domo CLI运行一些脚本化的Domo命令。
操作方法是将想要运行的命令放入脚本文件中,然后使用 -script
选项来运行它。
例如,将以下内容放入名为 /path/to/myscript.domo
的文件中:
connect -s yourdomain.domo.com -t mytokenhere
query-data -i datasetid -sql "SELECT * FROM `hs_users_raw`" -xf test3.csv
然后使用 domoUtil.jar
来运行脚本,方法如下:
java -jar domoUtil.jar -script /path/to/myscript.domo
这在 CLI 工具的 文档 中有解释。
你当前的方法无法工作的原因是 &&
不起作用。实际上,
A && B && C
告诉 shell 执行以下操作:
- 运行 shell 命令 A
- 如果 A 返回零返回码,运行 shell 命令 B
- 如果 B 返回零返回码,运行 shell 命令 C
这对你不起作用,因为 connect
和 query-data
不是 shell 命令。它们是 CLI 要运行的命令。此外,在向 CLI 发出连接和查询命令之前,你不希望等待 CLI 返回返回码(即完成)。
Domo CLI(可能)希望从其标准输入中读取命令。因此,以下内容 可能 作为替代方法(在 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
在 Windows 批处理语言中可能有一个等效的方法。
无论如何,-script
方法是 Domo 手册推荐的方法。
英文:
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:
- run shell command A
- if A returns a zero return code, run shell command B
- 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 (i.e. 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论