【问题标题】:Naked.toolshed not sending all the parameters infoNaked.toolshed 未发送所有参数信息
【发布时间】:2021-06-11 12:55:52
【问题描述】:

这是我在 python 中的代码的一个小例子:

from Naked.toolshed.shell import execute_js, muterun_js

caption=str("fsf sfsggs")

link="sggdhbwdhsrh"

print(caption)

arg_in = f"{link} {caption}"

response = execute_js('C:/Users/Me/AppData/Roaming/npm/node_modules/t.js', arg_in)

然后打印这些参数的 js 代码只是为了查看脚本是否按照应有的方式接收信息:

var link = process.argv[2]

var caption= process.argv[3]

console.log(caption)

但是我只得到了 cmd 中的第一个单词:

fsf

【问题讨论】:

    标签: javascript python arguments parameter-passing command-line-arguments


    【解决方案1】:

    命令行参数由空格分隔,因此caption 值被拆分为 2 个参数。

    你只记录process.argv[3],这实际上是5的第四个参数。你可以用console.log(process.argv)查看它们...

    [
      'C:\\Program Files (x86)\\nodejs\\node.exe',
      'E:\\proj\\so\\t.js',
      'sggdhbwdhsrh',
      'fsf',
      'sfsggs'
    ]
    

    数组元素索引是从零开始的(当然!)。所以sfsggsprocess.argv[4]

    如果您想将caption 作为一个包含空格的参数传递,那么在Python 中您可以将" 括在语音标记中,就像这样...

    caption='"fsf sfsggs"'
    

    【讨论】:

    • 没问题 :-)
    • 准备好后,请随时accept这个答案;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    相关资源
    最近更新 更多