You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was unsure if this was an issue or an oversight by me, so I opened it as a Q&A.
I want to run multiple commands chained (sequentially) in the background using python variables, so that I can start multiple of these in parallel and collect them via $jobs later.
In shell script this works fine with the help of paranthesis:
sleep 1 &&echotest# Echos "test" and then the shell resets (no background process)
(sleep 1 &&echo test) &# The shell resets and then echos "test" on top of the prompt
Trying to achieve the same in xonsh:
(sleep 1 &&echo test) &# Also works as expected and as the above# Using env variables$a = 1
$b = "test"
sleep $a&&echo$b# Works as the shell script example
(sleep $a&&echo$b) &# Same as the shell example, while running in background
However I am unable to replace the whole sleep 1 expression as $cmd = 'sleep 1' and then running $($cmd), right? At least I can't get it to work.
The issue comes with python variables, as the variables seem to become unknown (a different scope?)
a = 1
b = "test"
sleep @(a) &&echo@(b)
# Works the same as the above# Trying to run it in background
(sleep @(a) &&echo@(b)) &# NameError: name 'a' is not defined
Because this doesn't work, my full python commands don't work either, e.g.
a = ["sleep", "1"]
b = ["echo", "test"]
(@(a) &&@(b)) &
The ampersand seems to break it and it works fine without (except that it doesn't run in background).
Does anyone have suggestions on how to circumvent this problem?
I could bind the arguments of the command as temporary env variables and then run
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was unsure if this was an issue or an oversight by me, so I opened it as a Q&A.
I want to run multiple commands chained (sequentially) in the background using python variables, so that I can start multiple of these in parallel and collect them via
$jobs
later.In shell script this works fine with the help of paranthesis:
Trying to achieve the same in xonsh:
However I am unable to replace the whole
sleep 1
expression as$cmd = 'sleep 1'
and then running$($cmd)
, right? At least I can't get it to work.The issue comes with python variables, as the variables seem to become unknown (a different scope?)
Because this doesn't work, my full python commands don't work either, e.g.
The ampersand seems to break it and it works fine without (except that it doesn't run in background).
Does anyone have suggestions on how to circumvent this problem?
I could bind the arguments of the command as temporary env variables and then run
but that doesn't look like a nice solution.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions