What is the process for launching an external application from my vscode extension?

After compiling and running the TypeScript code below, the application named Notion will open:

const cmd = 'open -a "/Applications/Notion.app"';
exec(cmd, (error, stdout, stderr) => {});

If I try running the same code within my extension.ts file, the command is executed but Notion does not open. Nothing happens, there's no output from the open command in terms of stdout, stderr, or error messages. This issue also occurs with other applications.

import * as vscode from 'vscode';
import {exec} from 'child_process'

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('helloworld.helloWorld', () => {
        const cmd = 'open -a "/Applications/Notion.app"';
        vscode.window.showInformationMessage(`Running command: ${cmd}`);
        exec(cmd, (error, stdout, stderr) => {});
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {}

Is there a way to successfully open an external application from within my vscode extension?

Answer №1

It appears that certain environment variables set for subprocesses during the execution of an extension are causing issues with opening applications. By clearing all environment variables from the subprocess, I was able to successfully open external applications within my extension.

const newOptions = {env: {}};
execute(command, newOptions, (err, output, error) => {});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hide the div in PHP if the active variable is null

It looks like I'll need to implement Jquery for this task. I have a print button that should only appear if my array contains data. This is a simplified version of what I'm aiming to achieve: HTML <?include 'anotherpage.php'?> ...

Prevent automatic scrolling to the top following an AJAX request

Question about Preventing Scrolling to Top: How can I prevent a web page from scrolling to the top when a link triggers javascript? Whenever an ajax request occurs, my browser automatically scrolls to the top. In order to return to my desired div sect ...

Calculating the hour difference between two time stamps (HH:MM:SS a) using moment.js

I have two time without date var startTime="12:16:59 am"; var endTime="06:12:07 pm"; I need to calculate the total hours between the above times using a library like moment.js. If it's not achievable with moment.js, then please provide a solution u ...

How to set the type of an object property to a string based on a string from an array of strings in TypeScript

Great { choices: ['Bob', 'Chris', 'Alice'], selectedChoice: 'Alice', } Not So Good { choices: ['Bob', 'Chris', 'Alice'], selectedChoice: 'Sam', } I've been exp ...

suggestions for customizing Angular Material

The guidelines regarding materials specify that: "For any Angular Material component, you are allowed to define custom CSS for the component's host element that impacts its positioning or layout, such as margin, position, top, left, transform, and z- ...

Reviewing for the presence of "Undefined" in the conditional statement within Transpiled Javascript code for

While perusing through some transpiled Angular code, I came across this snippet: var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { I'm puzzled by the usage of undefined in this context. Can an ...

What could be causing JavaScript's wrapInner function to throw an error?

Somehow, the Firefox add-on I've been working on isn't functioning as expected. The initial line of code is executing without issues, which wraps content in a div element with an id of 'content_cont'. However, any subsequent lines of co ...

Changes to the model cannot be realized unless $scope.$apply is used

Are there alternative methods to achieve the desired model change without utilizing $scope injection in an Angular "controller as" approach within the given setup? The HTML: <div data-ng-controller="Buildings as vm"> <select data-ng-model="vm. ...

What is the solution to determining the accurate span form value?

The script below calculates a simple sum, displaying an error if the sum exceeds or falls below 100. Despite the error message, the user can still proceed to the next page. I want to restrict the user from moving to the next page until the sum equals 100 ...

What is the best way to showcase several images using Sweet Alert 2?

In the process of developing my Angular 2 application, I have incorporated sweet alert 2 into certain sections. I am looking to showcase multiple images (a minimum of two) at the same time in the pop-up. Does anyone have any suggestions on how to achieve ...

What is the best way to receive a response from the foo.onload = function() function?

My current code involves a function that is triggered by .onload, and I'm looking to return a specific value based on certain conditions: newImg.onload = function() { var height = newImg.height; var width = newImg.width; if(height > wi ...

What are the steps to implement zone.js in your Angular application?

I am looking to utilize zone.js in my Angular project beyond just the runOutsideAngularZone function. My attempt to include it looked like this: import { zone } from 'zone.js'; Unfortunately, I encountered this error: error TS2306: File &apos ...

Building an anchor tag that employs the HTTP DELETE method within an Express.js app

Recently, I delved into using express.js with handlebars.js as my template engine. One task I wanted to tackle was creating a delete link that followed RESTful principles and used the HTTP DELETE verb instead of GET. After some trial and error, I discover ...

Creating a data type restricted to utilizing property names exclusively from a specified string union:

I have a specific Enum: enum MyEnum { optionOne = 0, optionTwo = 1, optionThree = 2, optionFour = 3, } and a related Type: export type EnumNamesList = keyof typeof MyEnum; I am looking to create a type similar to this: export type EnumDataTypes = ...

Issues have been encountered with the functionality of $rootScope

I am currently struggling with a code snippet in my loginCtrl.js file where I can't seem to get $rootScope to store the value of vm.userEmail. app.controller('LoginCtrl', function($timeout, $q, $log, $rootScope /*$auth*/, $location, $mdTo ...

Error encountered with Google Places API due to Cross-Origin Resource Sharing

I have encountered an issue with my function that involves using AJAX to call the Google Places API. Despite the fact that the API supports CORS for both client and server, I am still receiving a CORS error. Unfortunately, JSONP is not a viable solution in ...

Implementing Gatsby-js for client-side JavaScript directly within a blog post is a powerful

I've been working on setting up a blog using Gatsby-JS and have run into a bit of an issue. My posts, written in markdown, include inline javascript like this: <script>window.alert("hello");</script> When I test the site with "Gatsby ser ...

What is the method for showcasing a single Observable from an Array of Observables in Angular?

I am facing a challenge with displaying questions from an Observable-Array one by one. Currently, I can only display all the questions at once using *ngFor in my HTML. Here is my component code snippet: import { Component, OnInit } from '@angula ...

Failure in retrieving values from AngularFire2 Subscribe

I am encountering an issue with the code in my authService constructor( private afAuth: AngularFireAuth, private db: AngularFireDatabase, private router: Router ) { this.authState = afAuth.authState; this.authState.subscribe((use ...

Is there a counterpart to ES6 "Sets" in TypeScript?

I am looking to extract all the distinct properties from an array of objects. This can be done efficiently in ES6 using the spread operator along with the Set object, as shown below: var arr = [ {foo:1, bar:2}, {foo:2, bar:3}, {foo:3, bar:3} ] const un ...