Post B5l0Xx9VERFAqeBlEu by stib@aus.social
(DIR) More posts by stib@aus.social
(DIR) Post #B5l0Xx9VERFAqeBlEu by stib@aus.social
0 likes, 0 repeats
This is old news to anyone with actual command-line skills, but it saved me today when doing a Blender render that kept crashing. I normally render from the command line because it means I can keep posting toots, er, I mean working productively for my employer in the foreground while it's rendering, and because it's usually faster (especially if you can run multiple instances). Since I set up my scene to render an image sequence with overwriting turned off I can restart the render each time and pick up where it left off. But because command line, I can automate that process. In zsh (it will probably work on Bash or other shells I dunno) I do:`blender -b '/path/to/my/project.blend' -a; while [[ $? != 0 ]]; do; echo "!!!! Oh bollocks !!!!"; blender -b '/path/to/my/project.blend' -a; done`The guts of it is the `while` loop. This will loop as long as `$?` is not equal to 0. `$?` is a variable that holds the result of the previous operation, which is 0 if the previous operation succeeds. So if blender crashes it returns some non-zero return code, and the loop starts it up again.For info on rendering from the command line: https://docs.blender.org/manual/en/latest/advanced/command_line/render.html#blender #ShellScripting #CommandLine---EDIT----Check the replies for a more terse and elegant way to do this. Also, here's a screenie of it in action, you can see it crashing and then starting again. This is on OSX so there's a dialog box that pops up, luckily the shell ignores the user's rsponse and continues anyway.1/2
(DIR) Post #B5l0XxWXqlfw06yA9g by trouble@masto.ai
0 likes, 0 repeats
@stib I'm not sure this will work in zsh (there are a LOT of shells), but bash supports:while ! blender... ; do echo "Bollocks!" ; donewhile executes whatever follows, and if it exits zero, that means continue. The '!' inverts that (this is not in the original bourne shell, but it is in bash), so while NOT successful, echo, then go again.For example, the old shell scripting "if [" syntax? guess what: /bin/[ exists! (been that way for decades).
(DIR) Post #B5l0XxjJ5JsqdgwM2y by stib@aus.social
0 likes, 0 repeats
@trouble Yep, that works in zsh, I tried: `while ! foobar; do echo "ohai"; foobar; done`
(DIR) Post #B5l0XxtaT66h9ZkZ4S by trouble@masto.ai
0 likes, 0 repeats
@stib if you notice I only include blender once. It's not required a second time
(DIR) Post #B5l0Xy4DpYc7gYj3eC by stib@aus.social
0 likes, 0 repeats
@trouble ah, gotcha. Is there a difference between `while ! <cmd>` and `until <cmd>`?
(DIR) Post #B5l0XyCNLF8U5qXZM8 by trouble@masto.ai
0 likes, 0 repeats
@stib You are correct! "until" and "while !" are equivalent. I've used unix for years, and I either didn't know or completely forgot that "until" existed in bourne shell and family. Even old dogs can learn new tricks.
(DIR) Post #B5l0XyQYUWTinpAtSS by bobjonkman@mastodon.sdf.org
0 likes, 0 repeats
@troubleI thought there was a difference: "while" evaluates the conditional before the statement; "until" evaluates the conditional after the statement. So "until" executes the statement at least once, but "while" executes the statement zero or more times.Now, this may be a Pascal-ism. The construct for "until" put conditional at the end of the statement block. Bash and othet shells might be different.@stib#Pascal #Bash #ShellProgramming
(DIR) Post #B5l0XyeNf7XNUhdw0W by lanodan@queer.hacktivis.me
0 likes, 0 repeats
@bobjonkman @trouble @stib Checking POSIX, while ! foo; do bar; done and until foo; do bar; done seem equivalent.I think the difference you're going for would be more if shell had a do { bar } while foo construct.https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_09_04_09
(DIR) Post #B5l0Y4Rq6f4RTXp0IC by stib@aus.social
0 likes, 0 repeats
For more bells and whistles I've added a function that looks for orphaned placeholder files:`blender -b /path/to/my/project.blend -a; while [[ $? != 0 ]]; doecho "\n############## oh bollocks ##############\n"; find "/path/to/my/render/folder/" -size -1k -delete; blender -b /Volumes/4TB-Fastboi/MV11834-Halloween\ Cards\ 2025/Project\ Files/Bat/bat1.blend -adone`This deletes all files smaller than 1k (obviously don't do this if you're rendering very small images) using the `find` command and `-size -1k` as the parameter.There are also command line programs like imagemagick or pngcheck that can check images, you could run these to check through all the rendered files to make sure they're not corrupted. I've done that in the past when having issues rendering using multiple machines.
(DIR) Post #B5lT7hEEi6n0bTEcLI by bobjonkman@mastodon.sdf.org
1 likes, 0 repeats
@lanodanYes, 'do {bar} while (foo)' is more familiar.It's been a while since I saw #Pascal code. Not since Uni, two-thirds of a lifetime ago.@stib @trouble