How to invoke external command from within Kotlin code?

Example of running a git diff by shelling out: “git diff”.runCommand(gitRepoDir) Here are two implementations of the runCommand extension function: 1. Redirect to stdout/stderr This wires any output from the subprocess to regular stdout and stderr: fun String.runCommand(workingDir: File) { ProcessBuilder(*split(” “).toTypedArray()) .directory(workingDir) .redirectOutput(Redirect.INHERIT) .redirectError(Redirect.INHERIT) .start() .waitFor(60, TimeUnit.MINUTES) } 2. Capturing output as a String … Read more

How to execute file I’m editing in Vi(m)

There is the make command. It runs the command set in the makeprg option. Use % as a placeholder for the current file name. For example, if you were editing a python script: :set makeprg=python\ % Yes, you need to escape the space. After this you can simply run: :make If you wish, you can … Read more

Running a Python script from PHP

Tested on Ubuntu Server 10.04. I hope it helps you also on Arch Linux. In PHP use shell_exec function: Execute command via shell and return the complete output as a string. It returns the output from the executed command or NULL if an error occurred or the command produces no output. <?php $command = escapeshellcmd(‘/usr/custom/test.py’); … Read more

node.js execute system command synchronously

Node.js (since version 0.12 – so for a while) supports execSync: child_process.execSync(command[, options]) You can now directly do this: const execSync = require(‘child_process’).execSync; code = execSync(‘node -v’); and it’ll do what you expect. (Defaults to pipe the i/o results to the parent process). Note that you can also spawnSync now.

Differences between fork and exec

The use of fork and exec exemplifies the spirit of UNIX in that it provides a very simple way to start new processes. The fork call basically makes a duplicate of the current process, identical in almost every way. Not everything is copied over (for example, resource limits in some implementations) but the idea is … Read more

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