最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing arguments to execFile in node - Stack Overflow

programmeradmin2浏览0评论

I am trying to connect to browserstack using their binary and passing my key as an argument. if I do this in a terminal window:

./BrowserStackLocal --key ${BROWSERSTACK_KEY} 

Connection succeeds, my key is passed as expected. However I wish to run this binary via node using execFile. Below is my code

const { execFile } = require('child_process');
function getConnection() {
    execFile('./BrowserStackLocal', ['--key ${BROWSERSTACK_KEY}'], (err, stdout, stderr)  => {
        if (err) {
            console.log(err);
        } else
            console.log(stdout);
    });
}

However when I run my function I get the following:

BrowserStackLocal v7.1

 *** Error: Atleast one argument is required!

To test an internal server, run:
./BrowserStackLocal --key <KEY>
Example:
./BrowserStackLocal --key DsVSdoJPBi2z44sbGFx1

To test HTML files, run:
./BrowserStackLocal --key <KEY> --folder <full path to local folder>
Example:
./BrowserStackLocal --key DsVSdoJPBi2z44sbGFx1 --folder /Applications/MAMP/htdocs/example/

So it does not see my key. I have followed the guide here: .html#child_process_child_process_execfile_file_args_options_callback and I thought I was passing the argument in the correct manner, but I am obviously doing something wrong. Can someone help me out here? Thanks!

I am trying to connect to browserstack using their binary and passing my key as an argument. if I do this in a terminal window:

./BrowserStackLocal --key ${BROWSERSTACK_KEY} 

Connection succeeds, my key is passed as expected. However I wish to run this binary via node using execFile. Below is my code

const { execFile } = require('child_process');
function getConnection() {
    execFile('./BrowserStackLocal', ['--key ${BROWSERSTACK_KEY}'], (err, stdout, stderr)  => {
        if (err) {
            console.log(err);
        } else
            console.log(stdout);
    });
}

However when I run my function I get the following:

BrowserStackLocal v7.1

 *** Error: Atleast one argument is required!

To test an internal server, run:
./BrowserStackLocal --key <KEY>
Example:
./BrowserStackLocal --key DsVSdoJPBi2z44sbGFx1

To test HTML files, run:
./BrowserStackLocal --key <KEY> --folder <full path to local folder>
Example:
./BrowserStackLocal --key DsVSdoJPBi2z44sbGFx1 --folder /Applications/MAMP/htdocs/example/

So it does not see my key. I have followed the guide here: https://nodejs/api/child_process.html#child_process_child_process_execfile_file_args_options_callback and I thought I was passing the argument in the correct manner, but I am obviously doing something wrong. Can someone help me out here? Thanks!

Share Improve this question edited Apr 30, 2018 at 16:15 T.J. Crowder 1.1m200 gold badges2k silver badges1.9k bronze badges asked Apr 30, 2018 at 16:12 user1523236user1523236 1,4733 gold badges23 silver badges43 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 8

The array ['--key ${BROWSERSTACK_KEY}'] passes a single mand-line argument containing a space to the process. To pass two mand-line arguments (what it probably expects), use two strings:

execFile('./BrowserStackLocal', ['--key', '${BROWSERSTACK_KEY}'], ...

I presume ${BROWSERSTACK_KEY} is just your placeholder in the question for the actual key...

发布评论

评论列表(0)

  1. 暂无评论