A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label commandline. Show all posts
Showing posts with label commandline. Show all posts

Windows command prompt get set environment variables

Yuck. I feel dirty writing about the Windows command line, but sometimes you just need to get a job done.

View all environment variables

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

View a specific environment variable, e.g. PATH

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH

Set an env var locally (not persistent)

set FOO="foo"

Set an env var globally (persistent) - must be run as administrator

setx BAR "bar" /M

View individual local env vars

echo %FOO%

echo %BAR%


How to set network proxy from command line in Ubuntu

You might need to do this if your network settings dialog box crashes as I've seen on Ubuntu 13.10:

gsettings set org.gnome.system.proxy autoconfig-url http://myserver/myconfig.pac
gsettings set org.gnome.system.proxy mode auto

This is how I found out the settings:

$ for key in $(gsettings list-keys org.gnome.system.proxy); do echo $key = $(gsettings get org.gnome.system.proxy $key); done

autoconfig-url = 'http://myserver/myconfig.pac'
ignore-hosts = ['localhost', '127.0.0.0/8']
mode = 'auto'
use-same-proxy = false

It doesn't have to be a .pac file, ours is .dat.

(source)

How to use Saxon XSL 2 processor

java -jar saxon9he.jar -xsl:/path/to/file.xsl -s:/path/to/file.xml -o:/path/to/output.xml parameter1='value1' parameter2='value2'

Ping a host, then sleep and loop in Windows

@echo off
for /L %%a in (1,1,2016) do (
date /t
time /t
ping -n 30 yahoo.co.uk
ping localhost -n 360 > nul
)

Pipe this into a file to test your internet connection.
It pings yahoo.co.uk 30 times, then sleeps for 5 minutes.
It repeats 2016 times; That is one week.

Emacs and Cygwin

Can't quit emacs from cygwin?

From within Cygwin, if you start xemacs with: xemacs -nw (for No Window), then C-x C-c to quit emacs does not work. Instead you must type C-g to exit.

PHP command line

php -f file.php

file.php contains:
<?php
print "hello world";
?>

or a one-liner:

php -r "some code;"

Don't forget the trailing semicolon.