我正在尝试运行一个脚本,该脚本将被一些其他软件调用,以运行一些参数来获取目标值。
脚本run.sh如下:
#!/bin/bash
set -e
ssh id@somehost '
/path/to/folder/solver arg1 arg2 arg3
res=$(</path/to/folder/res_data.txt)
echo "Final Result:"
echo "1 $res"
'运行此文件将导致以下结果:
$ sh run.sh
OpenNN Exception: NeuralNetwork class.
void load(const std::string&) method.
Cannot load XML file ../data/neural_network.xml.
Final Result:
1 -285361 3.22136
Connection to somehost closed.上面的最终结果来自之前的输出
如果我在没有ssh的情况下运行类似的脚本
set -e
/path/to/folder/solver arg1 arg2 arg3
res=$(</path/to/folder/res_data.txt)
echo "Final Result:"
echo "1 $res"结果:
$ sh run.sh 7 26 100
Final Result:
1 -285361 3.22136
$ sh run.sh 7 26 150
Final Result:
1 -421429 5.16397有谁知道怎么解决这个问题吗?
发布于 2019-12-17 23:00:21
根据上面的注释,我得到了错误的解决方案,
#!/bin/bash
set -e
ssh id@somehost '
cd /path/to/folder/
./solver '$1' '$2' '$3'
res=$(<./res_data.txt)
echo "Final Result:"
echo "1 $res"
'我很简单,只需添加cd /path/to/folder/并从它看起来有效的文件夹中运行脚本,此外,我还用参数而不是./solver $1 $2 $3修复了这个问题,并使用./solver '$arg1' '$arg2' '$arg3'作为传递输入参数的方法来在求解器上运行。
以下输出来自上述更正后的文件
$ sh run.sh 7 26 100
Final Result:
1 -285361 3.22136
$sh run.sh 7 26 150
Final Result:
1 -421429 5.16397https://stackoverflow.com/questions/59375937
复制相似问题