Run function from the command line

With the -c (command) argument (assuming your file is named foo.py): $ python -c ‘import foo; print foo.hello()’ Alternatively, if you don’t care about namespace pollution: $ python -c ‘from foo import *; print hello()’ And the middle ground: $ python -c ‘from foo import hello; print hello()’

How To: Execute command line in C#, get STD OUT results

// Start the child process. Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = “YOURBATCHFILE.bat”; p.Start(); // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output … Read more

How can I pass an argument to a PowerShell script?

Tested as working: #Must be the first statement in your script (not counting comments) param([Int32]$step=30) $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + $step } Call it with powershell.exe -file itunesForward.ps1 -step 15 Multiple parameters syntax (comments are optional, but allowed): <# Script description. Some notes. #> param ( … Read more

How to count total lines changed by a specific author in a Git repository?

This gives some statistics about the author, modify as required. Using Gawk: git log –author=”_Your_Name_Here_” –pretty=tformat: –numstat \ | gawk ‘{ add += $1; subs += $2; loc += $1 – $2 } END { printf “added lines: %s removed lines: %s total lines: %s\n”, add, subs, loc }’ – Using Awk on Mac OSX: … Read more

How can you find and replace text in a file using the Windows command-line environment?

A lot of the answers here helped point me in the right direction, however none were suitable for me, so I am posting my solution. I have Windows 7, which comes with PowerShell built-in. Here is the script I used to find/replace all instances of text in a file: powershell -Command “(gc myFile.txt) -replace ‘foo’, … Read more

How to colorize diff on the command line

Man pages for diff suggest no solution for colorization from within itself. Please consider using colordiff. It’s a wrapper around diff that produces the same output as diff, except that it augments the output using colored syntax highlighting to increase readability: diff old new | colordiff or just: colordiff old new Installation: Ubuntu/Debian: sudo apt-get … Read more

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