Closed HenrikBengtsson closed 3 years ago
You may use ENV['VAR_NAME']
; it is a global constant.
On Wed, Dec 30, 2020, 2:24 PM Henrik Bengtsson notifications@github.com wrote:
At the bottom of https://ucsf-cbi.github.io/c4/scheduler/envvars.html we have Bash, Python, and R examples on how to get the numeric value of environment variable SLURM_NPROCS, e.g.
import osnslots = os.getenv('SLURM_NPROCS', '1') # env var is always a 'str'nslots = int(nslots) # coerce to 'int'print('Number of slots available: ' + nslots)
@AaronHechmer/@graft https://github.com/graft, as our Ruby experts, what's a corresponding example for Ruby?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/UCSF-CBI/c4/issues/34, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACHPA6NW6GV3ZHXNCJ352TSXOSAVANCNFSM4VOYZONA .
Thxs. And how do you coerce that string into an integer and assign it to a local variable. I know ~0.1% Ruby
...and print a message that includes that parsed integer?
Sorry, I was sans keyboard earlier. A more complete example:
nslots = (ENV['SLURM_NPROCS'] || 1).to_i
puts "Number of slots available: #{nslots}"
On Wed, Dec 30, 2020, 3:33 PM Henrik Bengtsson notifications@github.com wrote:
...and print a message that includes that parsed integer?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/UCSF-CBI/c4/issues/34#issuecomment-752790357, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACHPA54ZRRX75Z6PCFGWTTSXO2FXANCNFSM4VOYZONA .
Thank you. I've add it to https://ucsf-cbi.github.io/c4/scheduler/envvars.html. Like for the other languages, I took the freedom the split it up into one line per "step" to make it more clear what is happening in each step.
As somebody who grew up just south of Montreal, I'm delighted to see "sans" used here, a useful addition to English along with "faire du shopping," "faire du peepee" and "pamplemousse." However, sans keyboard? That leaves a number of open questions. I'm surprised you saw the thread at all! But you saw the thread and had no keyboard? This happened to me once when Xingyue was babe. I left the room for thirty seconds and she dumped a bottle of pumped breast milk on the laptop keyboard. Was a couple days before I had a replacement keyboard in hand.
I'd hardly call myself a Ruby expert, but I still like it better than python and have the documentation bookmarked: https://ruby-doc.org/
From: Saurabh Asthana notifications@github.com Sent: Wednesday, December 30, 2020 4:59 PM To: UCSF-CBI/c4 Cc: Hechmer, Aaron; Mention Subject: Re: [UCSF-CBI/c4] Ruby: How to get environment variable? (#34)
Sorry, I was sans keyboard earlier. A more complete example:
nslots = (ENV['SLURM_NPROCS'] || 1).to_i
puts "Number of slots available: #{nslots}"
On Wed, Dec 30, 2020, 3:33 PM Henrik Bengtsson notifications@github.com wrote:
...and print a message that includes that parsed integer?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/UCSF-CBI/c4/issues/34#issuecomment-752790357https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_UCSF-2DCBI_c4_issues_34-23issuecomment-2D752790357-253E&d=DwQFaQ&c=iORugZls2LlYyCAZRB3XLg&r=kK5BO0vReqfwenBYZKoW0ij2itfL5-6M_LOhSaAH7sM&m=feM8MSYIykBlBB0I8bOEXKAv50swNo7DxUlqrYuKrvQ&s=xn5tybjCE5B_gmMp5jKvRAD6gvZtHlxws95XpXP4HuM&e=, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACHPA54ZRRX75Z6PCFGWTTSXO2FXANCNFSM4VOYZONAhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AACHPA54ZRRX75Z6PCFGWTTSXO2FXANCNFSM4VOYZONA-253E&d=DwQFaQ&c=iORugZls2LlYyCAZRB3XLg&r=kK5BO0vReqfwenBYZKoW0ij2itfL5-6M_LOhSaAH7sM&m=feM8MSYIykBlBB0I8bOEXKAv50swNo7DxUlqrYuKrvQ&s=4GKLbAUI8tAQQx9M_GEd0zY5xCTJrHQsP45I53ry6W8&e= .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_UCSF-2DCBI_c4_issues_34-23issuecomment-2D752805854&d=DwMFaQ&c=iORugZls2LlYyCAZRB3XLg&r=kK5BO0vReqfwenBYZKoW0ij2itfL5-6M_LOhSaAH7sM&m=feM8MSYIykBlBB0I8bOEXKAv50swNo7DxUlqrYuKrvQ&s=QdsAOpvxcV09BqjwPnniN0cLBtwaeGkByWo4zaES6EI&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AHAXZPS2VKB7VNJKKU5YERTSXPEIFANCNFSM4VOYZONA&d=DwMFaQ&c=iORugZls2LlYyCAZRB3XLg&r=kK5BO0vReqfwenBYZKoW0ij2itfL5-6M_LOhSaAH7sM&m=feM8MSYIykBlBB0I8bOEXKAv50swNo7DxUlqrYuKrvQ&s=3fKpuz5rt8k9oK3iYueQIEhVeYj77d37wr6-JcUYk5E&e=.
At the bottom of https://ucsf-cbi.github.io/c4/scheduler/envvars.html we have Bash, Python, and R examples on how to get the numeric value of environment variable
SLURM_NPROCS
, e.g.@AaronHechmer / @graft, as our Ruby experts, what's a corresponding example for Ruby?