Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive shell in Deno

Tags:

deno

In python, the following line results in an interactive shell which I can use like any terminal.

os.system("bash");

Typing exit here quits the shell and the python script continues to execute.

How can i do something like this in Deno?

Edit: I should have been a bit more verbose in my initial question. My intent is not just to run a shell command. I want to run an interactive shell which grabs input/output until I manually exit with exit command. Deno.run({cmd: ["bash"]}) does not do this.

like image 744
Sway Avatar asked Aug 25 '26 07:08

Sway


1 Answers

You need to wait for the process (the bash shell) to exit. To do this, you to need await process.status().

// run using 
// deno run --allow-run demo.js

const p = Deno.run({
  cmd: ["bash"],
})

const status = await p.status()
console.log(status)

If you want to do it the Deno REPL, then run-

await Deno.run({ cmd: ["bash"] }).status()
like image 55
Shivam Singla Avatar answered Aug 26 '26 22:08

Shivam Singla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!