Reputation: 583
I have developed a python script that launches few Node.js applications in different consoles. It works on Windows (python version 3.7.3) but can't make it working on Macs (3.7.4_1).
I keep scrolling the python documentation but don't see anything that would be an issue and couple of posts I find in stack overflow do not solve my issue.
Here is the error:
subprocess.Popen(['node', 'index.js'],
creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)
AttributeError: module 'subprocess' has no attribute 'CREATE_NEW_CONSOLE'
Here is the code:
def __runProject(self, project):
print(f'Starting project \'{project.projectName}\'...')
subprocess.Popen(['node', 'index.js'], creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)
os.chdir(self.__currentWorkingDirectory)
Thank you in advance!
Upvotes: 3
Views: 1364
Reputation: 388
Indeed the macOS terminal is different when it comes to running a command after opening a new one. The trick is to use the "open" command. The parameter should actually be a command file to run. So for running node with the parameter index.js the following code will create a command file (start_node.command) that launches node with the parameter from a new terminal:
with open("start_node.command", "w") as f:
f.write("#!/bin/sh\nnode index.js\n")
os.chmod('myfile', stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH)
subprocess.Popen(['/usr/bin/open', '-n', '-a', 'Terminal', 'start_node.command'], shell=False)
Upvotes: 2