I need a little time to study your 'strict mode' suggestion.
I used 'set -e' before but had problems with it.
Would you know how I could detect that input is cat'ed into
the script ? ($ cat snippet.c | runc -i). So that I can suppress 'Type your code then CTRL+D'.
> Would you know how I could detect that input is cat'ed into the script ? ($ cat snippet.c | runc -i). So that I can suppress 'Type your code then CTRL+D'.
This is not a complaint about the name. Just that as a command from the command line, "runc" may clash with the runc container running utility due to potential overlap in the likely users.
Again, it's not the project name just the potential clash at the OS level. Because over the years, I've done it to myself.
crun is actually a project that competes with runc. runc (run container) is implemented in go, and crun is a mostly drop-in reimplementation of it in C that is more faster and simpler, it's currently gaining traction in rhel/centos/fedora and suse linux as it was first to implement newer features such as cgroup v2.
Compiling and running C code in a single command (without using a Makefile/build system, etc. but by pulling a binary from Homebrew or whatever) feels like a 10x engineering goal, so I therefore put forward: 10cc
As a bonus, it can output "I don't like C code, I love it" in its help/version docs.
That wasn't quite what I was trying to show with the snippet - I was intimating that you can use tcc to run C directly in something like a shell script.
If you want to make `tcc -w -run` etc. more convenient then:
> That wasn't quite what I was trying to show with the snippet - I was intimating that you can use tcc to run C directly in something like a shell script.
I know, but the first example in the link was:
$ runc 'printf("%s\n", "Hello!");'
Hello!
So I figured I'd complement your example use with one that was more analogous to that.
> I can't edit my parent comment now, but it can be improved with e.g.
To be honest, I liked your original example more. Using that `//` "shebang" depends on what shell it's invoked from, and it wouldn't work when calling exec from other languages. For example, with your last example using `//`:
$ python -c 'import subprocess; subprocess.run(["./hello-tcc-double-slash-shebang.c"])'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: './hello-tcc-double-slash-shebang.c'
while it would work with the `#!` shebang, since that's handled by the kernel.
Reminds me of [1] "c" a utility which allows you to execute C code as if it were a script. It's a shame the name is almost unsearchable in Google though...
I'm sorry, I don't see the benefit of runc including a small list of headers for me. A small test program like main.c ought to be self-contained and might need headers not supplied by runc.
What is the big deal with just leaving the a.out alone? I might need to run it again, maybe with different arguments. A few a.out files from test programs are not exactly worth fussing over IMHO.
To each their own. If you're in vim, you don't need to leave your editor if you prepend an exclamation mark to the above expression. I often do a lot of prototyping with:
Couple of immediate issues with the repo:
- Sample output in the README should not be prefixed with a "$". That's only for the shell command prompt.
- Use ``` blocks in your README file. It's easier to format multi-line text.
- Don't use $RANDOM, it's not secure. Use mktemp: https://github.com/alcover/runc/blob/73aaecea5a4cd357f7172dd...
- Don't exit with success if the command failed: https://github.com/alcover/runc/blob/73aaecea5a4cd357f7172dd...
- Use Bash strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/