-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow offering dynamic script output for download #251
base: master
Are you sure you want to change the base?
Conversation
I think I'm still a little confused about what the behavior is, and where the inconsistency is from. What you're saying is when you do On macOS, running a text file with no shebang with I think adding a shebang automatically might not be desirable. It would make it unclear what was running a script without reading documentation, and it would mess up line numbers in error messages. Also if a user misspelled a shebang, i.e. added I think it would probably be okay to just chmod +x the script and run it, and let the user add the |
src/virtual_file.rs
Outdated
tokio::fs::write(&script_file, source).await.expect("fixme"); | ||
run!(%"chmod +x", &script_file); | ||
run!(%"cat", &script_file); | ||
let output = tokio::process::Command::new(script_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary to do now, but we should remember to check the status code of the script. Not sure what to do if it fails.
Co-authored-by: Casey Rodarmor <[email protected]>
I get:
Weird.
Yeah, good points. I think that sounds right. |
@casey: I was wrong about how processes get executed on linux: The kernel is capable of running scripts and binaries (e.g. ELF binaries), but in the case of scripts, they have to start with
#!
. So the kernel will not fall back on any shell, if the hashbang is missing. You can run scripts that don't start with#!
from e.g.bash
, and that will work by falling back on some shell, but that behavior is implemented in the shells you're using for that. (And apparently the exact behavior (e.g. which shell to use) depends on the parent shell being used.)So this PR right now implements the following logic: When the given script starts with
#!
it is executed unmodified. If it doesn't a hashbang line is added (#!/usr/bin/sh
). Judging from the tests that seems to be the behavior we want, but it's a bit magical.The PR still needs to be cleaned up a lot, but I wanted to get your feedback early.