簡體   English   中英

從TestCafe腳本轉義到shell

[英]Escape to shell from TestCafe script

我正在使用TestCafe腳本,我在其中捕獲需要用作shell / bash命令輸入的端點URL。

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

然后我想使用inputText來執行bash命令,說(為簡單起見)

echo inputText

如何通過我的testcafe腳本實現這一目標? 我找不到相關文檔的相關帖子。

我確實在Javascript上找到了一個使用process.createChildProcess('command');的相關帖子process.createChildProcess('command'); ,但我仍在嘗試使這個解決方案有效。 請參閱此處的文檔

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

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

我從下面開始使用它,從這個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