【问题标题】:Specific inputs of experiment return parser error实验返回解析器错误的具体输入
【发布时间】:2019-04-28 18:58:02
【问题描述】:
#!/bin/bash
for tracelength in 50 100 150 200 250 300 350 400 450 500 ; do
    step=0.2
    short=0
    long=1
    for i in {1..4}; do
    ratio=0
        for j in {1..4}; do
                declare -a listofresults
                echo "$tracelength $short $long $ratio" >> results.csv
                python3 main.py "$tracelength" "$short" "$long" "$ratio">file.smt2
                chmod 775 file.smt2
                declare total=0
                declare m=0
                for repeat in {1..10}; do
                    executiontime=$(timeout 500 gtime -f "%U" /Users/ouafaelachhab/Desktop/SemanticLocality/optimathsat-1.6.2-macos-64-bit/bin/optimathsat < file.smt2 2>&1 >/dev/null)
                    echo "$executiontime"
                    total=$(echo "scale=2; ($total) + ($executiontime)" | bc) #echo $(bc <<< "scale=2; $total/100")
                    echo "$total"
                    let "m=m+1"
                    echo "m=$m"
                done
                echo $(bc <<< "scale=2; ($total)/10") >> results.csv
                ratio=$(echo "scale=10; ($ratio) + ($step)" | bc) #float points arithmetics are different
            done
            short=$(echo "scale=10; ($short) + ($step)" | bc)
            long=$(echo "scale=10; ($long) - ($step)" | bc)
        done
    done

我基本上只是在运行一个带有变体输入的文件的实验。该代码适用于某些值,而对于某些值,它只是给了我:

(standard_in) 1: parse error

在我的结果文件中,这是我的输出:

50 0 1 0
21.82
50 0 1 .2
27.08
50 0 1 .4
40.89
50 0 1 .6

我正在运行的实验总是在相同的输入值处停止(输出文件中打印的最后一个值),然后从那里开始出现所有 解析器错误!为什么这样做?我该如何解决?我已经尝试了多种解决方案,我在这里找到了类似问题(与 bc 相关),但没有一个有效。

【问题讨论】:

  • 那么在这些情况下它会失败哪些值以及bc 的输入是什么?
  • 它就在那里!输入文件中的最后一个值:50 0 1 0.6 它会产生解析器错误,并且从那里它是所有解析器错误
  • 我的意思是说*输出文件
  • 我不确定我是否理解。您有五个命令,例如echo "something" | bc,当然它们通过构建和表达并将其传递给bc 来工作。你能找到哪一行产生了这个错误,你写到 bc 的字符串是什么? bash -x yourscript 是一种详细的查找方法

标签: bash macos shell bc optimathsat


【解决方案1】:

我怀疑它与以下行有关:

executiontime=$(timeout 500 gtime -f "%U" /Users/ouafaelachhab/Desktop/SemanticLocality/optimathsat-1.6.2-macos-64-bit/bin/optimathsat &1 >/dev/null)

当我用

更改您的代码时

executiontime="ISSUE"

我将其作为输出(注意 I S S U E 是如何逐行打印的)

m=3
问题
(standard_in) 1: 解析错误 (standard_in) 1:非法字符:I (standard_in) 1:非法字符:S (standard_in) 1:非法字符:S (standard_in) 1:非法字符:U

【讨论】:

  • 你在 echo "$executiontime" 得到了预期的格式吗?
  • 以下行必须更正.. executiontime=$(timeout 500 gtime -f "%U" /Users/ouafaelachhab/Desktop/SemanticLocality/optimathsat-1.6.2-macos-64-bit/bin/optimathsat &lt; file.smt2 2&gt;&amp;1 &gt;/dev/null) 因为它大致相当于executiontime=$(something 2&gt;&amp;1 &gt; /dev/null)
  • 我不明白你的意思?
  • executiontime=$(something 2>&1 /dev/null) 将始终给出 executiontime="" ... 因为 stderr(文件描述符 2)和 stdin(文件描述符 1)使用 " 2>&1" 然后它们的输出被发送到/dev/null,这意味着被内核“丢弃”。
猜你喜欢
  • 2017-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-17
相关资源
最近更新 更多