【问题标题】:Interpreting python program line by line from makefile从makefile逐行解释python程序
【发布时间】:2014-07-24 14:24:35
【问题描述】:

我需要逐行解释一个python程序。我在 python 中使用 -c 选项,并且有这样的 makefile。

all:   
python -c  
"print 'aa'  
   print 'bb'"

当我用 make 运行它时,我得到 ​​p>

python -c "print 'aa'
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [all] Error 2

当我取出相同的 python 行并从 bash 运行时,它工作正常。可能是什么问题?

【问题讨论】:

    标签: python bash makefile


    【解决方案1】:

    如果你的 Makefile 真的是

    all:   
    python -c  
    "print 'aa'  
       print 'bb'"
    

    我希望看到更多错误。使用该 makefile,make 将首先尝试运行 python -c,这应该会生成如下错误:Argument expected for the -c option。然后它将中止,甚至不会尝试运行 shell 命令"print 'aa'。您需要换行符和分号。

    all:   
            python -c   \
            "print 'aa';   \
            print 'bb'"
    

    分号是必要的,因为 make 会去掉所有换行符并将字符串 python -c "print 'aa'; print bb'" 传递给 shell(无论 SHELL 设置为什么)。

    【讨论】:

      【解决方案2】:

      make 规则的每一行都在不同的 shell 实例中执行。您需要转义换行符(使用\)或将其全部放在一行中。

      另外,给定的 makefile sn-p 应该会给你一个关于 -c 的意外参数的错误。您的错误表明您的 sn-p 实际上是:

      all:   
      python -c "print 'aa'  
         print 'bb'"
      

      这并没有改变任何东西。

      【讨论】:

        【解决方案3】:

        看看这个问题。我认为您的问题是您的程序跨越多行,但您的 makefile 并没有以这种方式解释它。添加斜线应该可以清除它。

        Multiline bash commands in makefile

        【讨论】:

          猜你喜欢
          • 2017-08-18
          • 2018-04-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-22
          • 2015-08-25
          • 1970-01-01
          相关资源
          最近更新 更多