简体   繁体   English

从TestCafe脚本转义到shell

[英]Escape to shell from TestCafe script

I am working on a TestCafe script where I capture an endpoint URL that needs to serve as an input for a shell/bash command. 我正在使用TestCafe脚本,我在其中捕获需要用作shell / bash命令输入的端点URL。

const inputText = await Selector('textarea[name="url-input"]').value;
console.info(`This is my URL of interest ${inputText}`)

Then I want to use inputText to execute a bash command, say (for simplicity) 然后我想使用inputText来执行bash命令,说(为简单起见)

echo inputText

How can this be accomplished from my testcafe script? 如何通过我的testcafe脚本实现这一目标? I couldn't find a related post of documentation on this. 我找不到相关文档的相关帖子。

I did find a related post on Javascript that uses process.createChildProcess('command'); 我确实在Javascript上找到了一个使用process.createChildProcess('command');的相关帖子process.createChildProcess('command'); , but I'm still trying to make this solution work. ,但我仍在尝试使这个解决方案有效。 See docs here 请参阅此处的文档

// on declarations
const { exec } = require('child_process');

// inside the test
exec('echo "The \\$HOME variable is $HOME"');

I got it to work with the following, from this 1 and this 2 . 我从下面开始使用它,从这个1这个2

// on declarations
const { exec } = require('child_process');

// inside the test
const inputText = await Selector('textarea[name="url-input"]').value;
exec(inputText,
    function (error, stdout, stderr) {
      console.log('stdout: ' + stdout);
      console.log('stderr: ' + stderr);
      if (error !== null) {
        console.error('exec error: ' + error);
      }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM