How to get local variables updated, when using the `exec` call?

This issue is somewhat discussed in the Python3 bug list. Ultimately, to get this behavior, you need to do: def foo(): ldict = {} exec(“a=3”,globals(),ldict) a = ldict[‘a’] print(a) And if you check the Python3 documentation on exec, you’ll see the following note: The default locals act as described for function locals() below: modifications to … Read more

Dynamic/runtime method creation (code generation) in Python

Based on Theran’s code, but extending it to methods on classes: class Dynamo(object): pass def add_dynamo(cls,i): def innerdynamo(self): print “in dynamo %d” % i innerdynamo.__doc__ = “docstring for dynamo%d” % i innerdynamo.__name__ = “dynamo%d” % i setattr(cls,innerdynamo.__name__,innerdynamo) for i in range(2): add_dynamo(Dynamo, i) d=Dynamo() d.dynamo0() d.dynamo1() Which should print: in dynamo 0 in dynamo 1

Redirecting exec output to a buffer or file

For sending the output to another file (I’m leaving out error checking to focus on the important details): if (fork() == 0) { // child int fd = open(file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); dup2(fd, 1); // make stdout go to file dup2(fd, 2); // make stderr go to file – you may choose … Read more

sh command: exec 2>&1

Technically speaking it duplicates, or copies, stderr onto stdout. Usually you don’t need the exec to perform this. A more typical use of exec with file descriptors is to indicate that you want to assign a file to an unused file descriptor, e.g. exec 35< my_input BTW Don’t forget that the sequence of declaration when … Read more

How do I launch a completely independent process from a Java program?

There is a parent child relation between your processes and you have to break that. For Windows you can try: Runtime.getRuntime().exec(“cmd /c start editor.exe”); For Linux the process seem to run detached anyway, no nohup necessary. I tried it with gvim, midori and acroread. import java.io.IOException; public class Exec { public static void main(String[] args) … Read more

What are the differences of system(), exec() and shell_exec() in PHP?

exec — Execute an external program system — Execute an external program and display the output shell_exec — Execute command via shell and return the complete output as a string so if you don’t need the output, I would go with exec. Further details: http://php.net/manual/en/function.exec.php http://php.net/manual/en/function.system.php http://php.net/shell_exec

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)