Program called to run via wine within a node.js script freezes - node.js

Program called to run via wine within a node.js script freezes as soon as it starts to do it's task.
This is the top output:
It runs fine and display the cli's header if I call it without parameters.
But if use it with arguments it hangs as soon as it starts to display progress and continuous stdout (eg: the ones where the only thing that is updated in the screen is the percentage of the current task)
Tried with exec, execSync, spawnSync, spawn.
Also tried to spawn and spawnSync a .sh file calling it (with and without & disown)
I think it has something to do with some child_process or even environment limitations, because I was able to do it by calling wine from a new gnome-terminal with parameters. But then I get an extra terminal window popping up, and no control whatsoever about the task conclusion.
Does anyone have a solution or a workaround for this?

It was related to stdio
No idea why, but setting
{stdio: ['inherit', 'pipe', 'pipe']} to .spawn() for Ubuntu and OSX did the trick.

Related

How to navigate from running python script in ubuntu terminal?

I am currently running a python3 script in Ubuntu server 18.04. When i type new commands into the command line it just prints the commands. My terminal window looks like this:
mitch#server:`$ cd /home/mitch/folder
mitch#server:`/folder$ python3 main.py
file running ...
text i input just shows like this
I need to keep the script running and run other commands, how do i navigate back to:
mitch#server:`
I'm new to servers/Ubuntu/commands so this may seem trivial! Thank you
So you can't "navigate" back to that, since you're technically already there, you're just running a script in your shell which is occupying your shell - think of it like you opened a program in full screen.
But you have a few options:
The most basic is to run the script in the 'background' this is a simple as adding a & to the end of your command (note that it will still send any message from the script into your terminal - if your script is programmed to send messages that is).
Another option is to use a terminal multiplex like which lets you have multiple terminals open, as well as split screen terminals and many other features. One of the more popular multiplexers is called tmux, just keep in mind that it does have a bit of a learning curve to it, but is extremely useful once you learn it.

How to run python scipt in the background(after user input) even if the terminal is closed

I have a python script that takes some inputs from the user & then executes the code based on the input. The code takes some time to complete; during this code runtime the user can close the terminal(the code is run from a Linux machine)
As soon as the user closes the terminal the script stops as well. I know there are options like nohup but it wouldn't accept any input(where input is required in my script).
How can I fix this?
Requirement is -
Run the script, enter the inputs
Let the code run in the background even if the terminal is closed
Also is there a way to write whatever is being printed in the terminal(during the script runtime) to some file
Linux's screen tmux served my purpose.
There is a work around possible,
you can split your programm into two parts.
And start your background task with:
import os
usr_inp=input("test input: ")
os.popen(f"python3 background_task.py {usr_inp} &")
This should start the other programm in the background, there you can use the input over the sys.argv[1] variable.
(Usually it's not recommended using os.popen)

After disown a process how can I again read the stdout of the running process

I have a c program which is running on linux. I applied some command for running the process in background after closing the terminal.
1. Pause program with `Ctrl-Z`,
2. Pull it into the background with `bg`
3. Then disown it.
Now i want to see the console output of this program which is still running.
How can I do it in linux?
If the terminal used to run the command has been closed and you are using a new one, I guess that the standard output of the background process was closed, so that you cannot do that.
A very simple way is to use screen.
Another way is to redirect output to a file when the command is run, and access the file later.

Running a node.js process in background after giving inputs to it

I have this node.js server which, once spawned, expects some input from stdin. The inputs shouldn't be given straight away: I need to wait for some event before giving them (e.g. a connection from somebody). If I give the commands and close the shell, the server shuts itself down. I would like to give the input to the server and close my shell (effectively leaving the server running).
I know that to run a process in background I need to do for example node my_server.js &, but this prevents the input from the command line. I would like to give this input AND then put it in background. Modules like forever puts it in the background automatically without letting me giving the inputs through stdin.
Moreover putting the script in background kills anyways the server when closing the shell.
Any suggestion?
Thanks
I did a quick test just using gedit in Ubuntu 12.04, and it worked.
Start your node app like so "node app.js arg1 arg2" however you want to and hit enter to start the program. Then hit CTRL-z once your program has started running. This gives you the terminal back but stops the process in the background. To let it run in the background now, simply "bg" and hit enter. This will let the process keep running now but in the background.
You can confirm you are still up with the command "ps -ef | grep node" which should show your program still running.
However, this does still leave the node process attached to the terminal window so when you close the terminal window it will close the process. But I think this will get you most of what you seem to be looking for quick and easy.
You asked for any suggestion, so here it is: make your server able to start without user interaction. The simplest way to do it is probably to create a file containing exactly the input needed by the server, then starting it like this:
node my_server.js < my_input.txt &
If the input needed depends on what the server outputs (ouch), use expect(1). If possible, subvert the whole thing and use a module like commander to get your inputs from the command line instead of stdin.

getting a program to return immediately at the command line so it's not tied to the shell that launched it

Some programs return immediately when launched from the command line, Firefox for example. Most utilities (and all the programs I've written) are tied to the shell that created them. If you control-c the command line, the program's dead.
What do you have to add to a program or a shell script to get the return-immediately behavior? I guess I'm asking two questions there, one for shell scripts and one for general, if they're different. I would be particularly interested to know if there's a way to get an executable jar to do it.
I'm almost embarrassed to ask that one but I can't find the answer myself.
Thanks!
start cmd
on Windows,
cmd &
on *nux
Here substitute
cmd = java -jar JarFile.jar
On *nux the fg and bg commands are your friends as well ...
You need to basically need to fork a process or create a new thread (or pretend to)
in *nux you can do this with an & after the command like this /long/script & or in windows you can create a BATCH file that executes your processes then exits (it does this naturally).
NOTE: there's no particularly good way to reference this process after you're forked it, basically only ps for the process list. if you want to be able to see what the process is doing, check out using screen (another linux command) that will start a session for you and let you "re-attach" to the screen.
to do this, install screen (sudo apt-get install screen or yum install screen). then type screen to create a new session (note, it will look like you didn't do anything). then, run your /long/command (without the &), then press CTRL + A + D (at the same time) to detach from it (it's still running!). then, when you want to re-attach, type screen -r.
Additionally, look for flags in any help message that allow you do this without using the above options (for instance in synergy you can say synergy --background)
A wrapper script consisting of nothing but:
your_prog_or_script &
Will launch the target and exit immediately. You can add nohup to the beginning of that line so it will continue running if the shell is exited.
For an executable program (as opposed to a shell script), on Linux/Unix use fork() and exec() and then exit the parent process, which will return to the shell. For details see the man pages, or some page like http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html.

Resources