2

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.

Sway
  • 317
  • 1
  • 7
  • There is [Deno.run()](https://deno.land/manual/examples/subprocess) function to do so. – Nur Apr 20 '21 at 05:25
  • Does this answer your question? [How do I run an arbitrary shell command from Deno?](https://stackoverflow.com/questions/62142699/how-do-i-run-an-arbitrary-shell-command-from-deno) – Nur Apr 20 '21 at 05:28
  • Edited the question to add more details - Deno.run does not result in a shell that is interactive. – Sway Apr 20 '21 at 06:08

1 Answers1

1

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()
Shivam Singla
  • 2,117
  • 1
  • 10
  • 22