LoginSignup
0
0

Denoでプロセス置換付きでshellを実行するには

Last updated at Posted at 2023-06-04

今回は、Denoでプロセス置換付きでshellを実行する方法がわかったのでシェアしたい。

スニペット:文字列を格納した変数の差分を確認する

const a = "hello\nworld";
const b = "ola\nworld";
const command = new Deno.Command("bash", {
  args: [
  "-c",
  `diff <(echo -e "${a}") <(echo -e "${b}")`,
  ],
});
const output = await command.output();
const diff = new TextDecoder().decode(output.stdout);
console.log(`diff check \n ${diff}`);

上記で、文字列を格納した変数の差分を確認するシェルを実行し結果を確認できる。

リファレンス

Deno.run と Deno.spawn と Deno.Command のどれを使えば良いのか
Deno.runは非推奨になるので代替手段(Deno.Command、dax)
bashのプロセス置換機能を活用して、シェル作業やスクリプト書きを効率化する
私の質問のスレッド@Deno Discord

謝辞

Deno Discordで私の素人質問に対して真摯に答えをくださった下記の人々に深く感謝します。
Hexagonさん、dsherretさん

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0