I am trying to run a program from cmd, but not as a child of the prompt. I have tried calling the program directly: program, but this starts it as a child process. I have tried start "" program, but this also starts it as a child process. Is this possible? I don't want the program to close when the prompt is closed.
Edit: This is not a duplicate question - start doesn't work in this case. I don't know enough to explain better, but some things to note:
The program in question doesn't open a new window
The path to the program contains spaces, so requires inverted commas. However, the inverted commas seem to suggest to start that the argument is intended to be the name of the new command window.
I need to pass switches to the program, which makes things a bit more complicated
Related
(Please, help me adjust title and tags.)
When I run connmanctl I get a different prompt,
enrico:~$ connmanctl
connmanctl>
and different commands are available, like services, technologies, connect, ...
I'd like to know how this thing works.
I know that, in general, changing the prompt can be just a matter of changing the variable PS1. However this thing alone (read "the command connmanctl changes PS1 and returns) wouldn't have any effect at all on the functionalities of the commands line (I would still be in the same bash process).
Indeed, the fact that the available commands are changed, looks to me like the proof that connmanctl is running all the time the prompt is connmanctl>, and that, upon running connmanctl, a while loop is entered with a read statement in it, followed by a bunch of commands which process the the input.
In this latter scenario that I imagine, there's not even need to change PS1, as the connmanctl> line could simply be obtained by echo -n "connmanctl> ".
The reason behind this curiosity is that I'm trying to write a wrapper to connmanctl. I've already written it, and it works as intended, except that I don't know how to properly setup the autocompletion feature, and I think that in order to do so I first need to understand what is the right way to write an interactive shell script.
I have a shell running in a Vte.Terminal widget (could be bash, zsh, or any other interactive shell), I would like to monitor it so as to know when the prompt is available and a new command can be started.
I can't seem to come up with a consistent method.
Here are the ideas I've thought of so far:
Monitor for child process exit.
Could work some of the time, but commands that use only built-ins wouldn't spawn a child. (example: "while true; do; echo test; done;") Also When a command is started in background the prompt would be available before the child exited.
Watch for prompt string in Vte output.
Two problems: 1. A simple prompt string such as "#>" could easily be outputted by some script and give a false positive. 2. Knowing what the prompt string is, is problematic.
Any other ideas or a way to get one of the above working?
What my purpose is.
I'm working on a terminal emulator and would like to change the icon based on whether the prompt is available. Also I am attempting to allow commands to be 'queued' to run when next possible.
I recognize that it is possible to run a script in the background if the code is encompassed by the syntax:
job1 = fork do
# functional code in script
end
Process.detach(job1)
Now I have attempted this format on many occasions and it has worked on each occasion to successfully place the script in the background, so that it does not terminate when the Terminal window is closed, however for this particular script (too large to include), it stubbornly remains tethered to its window, and terminates when that window is closed.
This makes no sense, so my questions:
Is there any Ruby programming construct which could keep a program tethered to a window and in the foreground? e.g. print function, which requires a window to print to (so may possibly effect things).
Is there a better alternative to the above-mentioned format for placing a script in the background, using code within that script.
I have seen tools to daemonize processes.
But I have seen that:
some_command &
Runs process in a daemonized way, is this way bad? how is this way called?
Update
My doubt is that I am calling that command inside an ssh session, will the process last after closing ssh session?
That's not daemonized, that's simply running it as a background process.
A true dameon is a lot more involved; see e.g. http://en.wikipedia.org/wiki/Daemon_(computer_software)#Creation.
The & is an important little character in UNIX; it means "run the command in the background"; i.e., detach it from the window it was started from, so it does not block the command line.
Should the program ever try to read from the terminal window, it will be suspended, until the user "brings it to the foreground"; i.e., brings it to the state it would have had without the & to begin with.
To bring a program to the foreground, use "fg" or "%". If you have more than one background job to choose from ("jobs" will show you), then use for example "%2" to choose the second one.
Important:
If you forget to give the & at the end of line, and the process blocks the command input to the terminal window, you can put the process in the background "after the fact", by using Ctrl-Z. The process is suspended, and you get the command prompt back. The first thing you should do then is probably to give the command "bg", that resumes the process, but now in the background.
http://www.astro.ku.dk/comp-phys/tutorials/background.shtml
Programs like vi, less, screen, when executed, they fill the terminal with their data, and then, if you press c - Z (or terminate the program) the terminal return as it was before the execution of these programs.
How usually a program do that? What is the correct terminology this kind of thing?
PS: The words used in the title may be not correct since I've no even idea about the terminology of this kind of things.
EDIT:
Thank to #Atropo I now know the correct name of these is foreground process,
but, how a program do that? How the program can clear the screen, do its writing and, at the end of the execution, let the shell reappear with all the old writings?
They're called foreground processes.
Usually a foreground processes show the user an interface, through which the user can interact with the program. So the user must wait for one foreground process to complete before running another one.
While you use a foreground process the shell prompt disappears until you close the process or you put it in the background.
By default CTRL-C generates SIGINT signal and CTRL-Z SIGTSTP:
https://en.wikipedia.org/wiki/Unix_signal
To change the behavior you can:
redefine or mask signal handler
disable the key combination for stdin http://linux.die.net/man/3/termios
close stdin descriptor (like daemons do)