What are shell form and exec form?

The docker shell syntax (which is just a string as the RUN, ENTRYPOINT, and CMD) will run that string as the parameter to /bin/sh -c. This gives you a shell to expand variables, sub commands, piping output, chaining commands together, and other shell conveniences. RUN ls * | grep $trigger_filename || echo file missing && … Read more

Runtime.exec on argument containing multiple spaces

Ok, this is not simply an update but also an answer so I’m filing it as one. According to all information I could find, the following should theoretically do it: String[] cmd = {“explorer.exe”, “/select,\”C:\New”, “”, “”, “”, “”, “”, “”, “Folder\file.txt\””}; The multiple spaces have been broken into empty strings and the array version … Read more

Checking if process still running?

If you’re doing it in php, why not use php code: In the running program: define(‘PIDFILE’, ‘/var/run/myfile.pid’); file_put_contents(PIDFILE, posix_getpid()); function removePidFile() { unlink(PIDFILE); } register_shutdown_function(‘removePidFile’); Then, in the watchdog program, all you need to do is: function isProcessRunning($pidFile=”/var/run/myfile.pid”) { if (!file_exists($pidFile) || !is_file($pidFile)) return false; $pid = file_get_contents($pidFile); return posix_kill($pid, 0); } Basically, posix_kill has … Read more

Dynamically filtering a pandas dataframe

If you’re trying to build a dynamic query, there are easier ways. Here’s one using a list comprehension and str.join: query = ‘ & ‘.join([‘{}>{}’.format(k, v) for k, v in limits_dic.items()]) Or, using f-strings with python-3.6+, query = ‘ & ‘.join([f'{k}>{v}’ for k, v in limits_dic.items()]) print(query) ‘A>0 & C>-1 & B>2’ Pass the query … Read more

Cannot change global variables in a function through an exec() statement?

Per the docs, the exec statement takes two optional expressions, defaulting to globals() and locals(), and always performs changes (if any) in the locals() one. So, just be more explicit/specific/precise…: >>> def myfunc(): … exec(‘myvar=”boooh!”‘, globals()) … >>> myfunc() >>> myvar ‘boooh!’ …and you’ll be able to clobber global variables to your heart’s contents.

Using Quotes within getRuntime().exec

Use this: Runtime.getRuntime().exec(new String[] {“sh”, “-l”, “-c”, “./foo”}); Main point: don’t put the double quotes in. That’s only used when writing a command-line in the shell! e.g., echo “Hello, world!” (as typed in the shell) gets translated to: Runtime.getRuntime().exec(new String[] {“echo”, “Hello, world!”}); (Just forget for the moment that the shell normally has a builtin … Read more