gpt4 book ai didi

javascript - CoffeeScript - 使用参数执行 bash 脚本

转载 作者:数据小太阳 更新时间:2023-10-29 06:02:03 24 4
gpt4 key购买 nike

我正在玩 GitHub 的 Hubot,我尝试在我的机器人工作中执行一个 bash 脚本。
我成功执行了我的脚本,但如果我向该脚本添加一些参数,它就无法正常工作。

{ spawn } = require 'child_process'
s = spawn './myScript.sh' + " url" + " title" <------- doesn't work due to args
s = spawn './myScript.sh' <------- alright without args
s.stdout.on 'data', ( data ) -> console.log "Output: #{ data }"
s.stderr.on 'data', ( data ) -> console.error "Error: #{ data }"
s.on 'close', -> console.log "'s' has finished executing."

如何将参数传递给我的脚本?
感谢帮助

最佳答案

如文档中所述:

http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

Spawn 将一个由您的不同参数组成的数组作为第二个参数。它看起来像这样:

s = spawn './myScript.sh', [url, title]

关于javascript - CoffeeScript - 使用参数执行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21830844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com