Open FedericoCeratto opened 5 months ago
@FedericoCeratto that’d be totally on the list to do. Great feature request!
Probably a good idea to have a way to refer to the spawned process by ID rather than the brute-force killall <name>
. Something like:
let pid = spawn $ some command $
...do some stuff...
kill pid
Probably a good idea to have a way to refer to the spawned process by ID rather than the brute-force
killall <name>
. Something like:let pid = spawn $ some command $ ...do some stuff... kill pid
maybe as builtin so every command executed in Amber in the script you have the PID saved in a array (internally) so from Amber side you can kill any process you executed.
But most commands run synchronously.
I suppose it might make sense for commands that fork themselves and run asynchronously as a daemon. docker
for example, or sshd
.
Perhaps this syntax?
$ sshd $ as pid1
....some code....
kill pid1
$ docker run -d somecontainer $ as pid2 failed {
echo "oh no"
exit 1
}
....some code....
kill pid2
But most commands run synchronously.
That's true, save the pid it will be very nice for the cases you mentioned.
The as
keyword is already used to cast values. How about with
?
$ sshd $ with pid1
kill pid1
$ docker run -d somecontainer $ with pid2 failed {
echo "oh no"
exit 1
}
kill pid2
Mm......"with" doesn't sound right. You're not creating it with a variable, you're storing a handle.
I know as
is used for casting, but it's not used there for casting. Why can't it be used in both contexts?
Mm......"with" doesn't sound right. You're not creating it with a variable, you're storing a handle. I know
as
is used for casting, but it's not used there for casting. Why can't it be used in both contexts?
It could be used there for casting. In fact it's used in the standard library. How about just proc
, process
, pid
keyword instead?
Same syntax, just pid
instead of as
?
$ sshd $ pid x failed {
exit 1
}
....some code....
kill x
@b1ek @Mte90 @FedericoCeratto @CymDeveloppement do you have better ideas for this syntax?
I like to use just pid
it is more simpler and compact.
Also what do you all think about this syntax that would work like the Python's with
:
// Runs the following command in the background:
with $ sshd $ {
// Do some code
} failed {
exit 1
}
// The command `sshd` is killed here once the code inside of the `with` block is completed
Alternatively:
with $ sshd $? {
// Do some code
}
I like it. Perhaps with an async option for programs that don't fork:
with async $ sleep 1000 $ { // run in background
...do something...
} // command is terminated
One of the features that keeps me in bash land is the quick (and dirty) process management for development, e.g.:
Having simple unobtrusive process management in Amber would be very nice!