How to open non integrated terminal window from vscode extension? - javascript

I am developing an extension for Visual Studio Code. I need to open a terminal window and run some command there (One after another finishes). Same as Terminal.sendText but not in integrated terminal. Is there a way to do that?
Update
The closest I've got is using:
const childProcess = spawn('node', ['--version'],{
shell: true,
detached: true,
windowsHide: false
});
And the problem is it closes automatically

You could possibly run the machine's terminal application and specify a command to run, like with mate-terminal, -e option. You could then run bash with certain startup commands How to invoke bash, run commands inside the new shell, and then give control back to user?

Related

Open new terminal in MacOSX and run node script

I have been trying to figure out how to open a new terminal window from a Node application and run a preset command or script there.
I can open the terminal window:
const { exec } = require('child_process')
exec('open -a Terminal ' + process.env.HOME)
And this works fine, I have done a bit of research but it seems I can only find examples directed to bash
Could anyone help me on this?
Thanks
One way to do this would be to place the commands you want to run in a shell script with the .command extension. By default, these files will be opened in the Terminal application on macOS. This is a bit of a workaround, but I think it achieves what you would like to do.
Say we have the file hello.js containing the following:
console.log("Hello World")
And the shell script run_node.command
#!/bin/bash
node hello.js
Running the command open run_node.command will open a new Terminal.app instance and run the shell script, which in turn runs the node command. The terminal will close when the script exits.

'node' is not recognized as an internal command or external, an executable program or a batch file

First of all, I wanted to learn Node.js, I opened my code editor then logged a simple word. but the problem is when I open my terminal I write :
node server.js
but it says :
'node' is not recognized as an internal command
or external, an executable program or a batch file.
I don't know how to fix the problem even in my editor's terminal.
Seems you haven't installed node on your system. Be sure if you have installed node or not.
Just open your terminal and type node
If you don't see a message like this Welcome to Node.js v14.12.0. then check this official download/setup link.
If you're using Ubuntu, then follow this link.
For any other Linux distro, just search Install node on <manjaro>.
Change with your distro name.

Cypress command-line tool not honoring arguments

I'm not using npm, so I've downloaded Cypress directly. I'm able to open the Cypress binary directly from the command line, but I can't make it run tests from the command line. Running Cypress run just opens the UI. Cypress run --project /path/to/my/project does open the project in the UI, but doesn't run it. Bizarrely, Cypress version doesn't display the version, it just opens the UI. Even Cypress this-is-not-a-command opens the UI without any errors.
You should use the cypress NPM package to run Cypress from the command line. The binary itself is not designed to be executed for anything other than global open mode. The cypress NPM package contains a command-line utility that makes cypress run, cypress open, and cypress version work like you expect.
If you really really really don't want to use the CLI supplied with the cypress NPM package, you can reference how the CLI translates your command line arguments:
in open mode: https://github.com/cypress-io/cypress/blob/develop/cli/lib/exec/open.js
in run mode: https://github.com/cypress-io/cypress/blob/develop/cli/lib/exec/run.js
Note that these APIs are internal and may change at any time.
So, to do cypress run --project /path/to/project directly on the binary, it would look like this:
cypress-binary --run-project /path/to/project

Issue related to running of New React App

I installed Nodejs(v 10.16.0 LTS) and then using Windows Powershell I run following commands
npx create-react-app my-app
cd my-app
npm start
The actual problem I am facing is that if PowerShell window is opened in the background, then my code works properly. But when I close PowerShell and reload Browser Tab, the error occurs which say
This site can’t be reached
localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall.
Kindly help me to figure out this issue. Thanks
When you close PowerShell window you terminate your React app as well, it has to stay opened. Running npm start kicks off local server with your app running. If you want to have possibility to have application running with terminal closed you can use libs like https://www.npmjs.com/package/forever, but I do not recommend that- it's easy to forget you have one app instance running already :)
When you run the command npm start, this is the expected behaviour. This command spawns a new npm instance in the directory from where you have executed it and directs it to start a server. The catch here is that the server runs as an attached process with PowerShell, by default and it is bound to terminate once you close the PowerShell window.
To manually detach a process from the terminal, we use an & after the command on a UNIX-based system (Linux, MacOS etc.) something like npm start &.In case of PowerShell, you can make use of a built-in function called Start-Process like this -
Start-Process -NoNewWindow npm start
If you'd like to read more about it, you can refer a blog post here - https://ariefbayu.xyz/run-background-command-in-powershell-8ea86436684e

webpack command of npm run dev from a new line

After finished specified command npm run dev, I can't again write new command in node console.
How can I continue to write from a new line?
Thanks, everybody for the help!
npm run dev in most cases is intended to keep running, detect changes, re-transpile files and (hot) reload the application. That's intended behavior, so don't panic.
You should leave that terminal untouched and simply open a second one if you want to do anything else.
You will have to open another terminal window. The reason is that webpack is now listening for changes - meaning the process in your current terminal window is still running.
Opening another terminal window will allow you to run other commands while the webpack process is still running.
I found the right way. CTRL+C, after need to choose stop or not the execution of processing of listening and then will get a new line.

Categories

Resources