Live Chat!

How to redirect output to a file as well as display it out

* * * * * 1 votos

December 6th, 2007 mysurface

To redirect standard output to a file is easy, you just need to use the redirection symbol, for example:
echo “hello world” > test.txt
But what if I want to display it out as well as store into a file?
Answer: tee
echo “hello world” | tee test.txt
Okay it seems very easy, how about append?
Related PostsDisplay & log command [...]

Posted in Text Manipulation, pipeline, python, tee | Hits: 32846 | 5 Comments »

Python: How to access ssh with pexpect?

* * * *   1 votos

November 25th, 2007 mysurface

I have research on how to access ssh using scripting language for quite sometimes. For python, there are three libs is in my list:
Twisted - an event-driven networking engine written in Python.
Paramiko - implements the SSH2 protocol for secure connections to remote machines.
Pexpect - spawn a child application and control it as if a [...]

Posted in python | Hits: 20861 | No Comments »

python: handle string from pipelines and list of param

* * * * * 1 votos

November 13th, 2007 mysurface

While I was searching ways to implement pipeline input for my python apps, I read an article from linuxjournal.com that mention about how easy that python can works with pipeline.
Here is the code quote from that article.
#! /usr/local/bin/python
import sys
sys.stdout.write(sys.stdin.read())
Well, I understand that served as a simple example to show how easy python can works with [...]

Posted in Developer, python | Hits: 19567 | 4 Comments »

python: how to identify the type of your variable

          0 votos

November 10th, 2007 mysurface

In python, every single variable is an object, every object must have a type, it is either data structure or class instances. Python’s variable can be dynamically change easily during runtime, for example
>>> d={1:’one’,2:’two’}
>>> print d
{1: ‘one’, 2: ‘two’}
>>> d=['one','two']
>>> print d
['one', 'two']

First line d is declare as dict data type, and after 3rd line, [...]

Posted in Developer, python | Hits: 19798 | 4 Comments »

Help yourself in python

          0 votos

October 31st, 2007 mysurface

If your computer science student, you study IT, click with technology, python is not a snake for you. It is a scripting-like programming language that are so famous today. You can type python into google, the first link is not about the reptile but the programming language. There are plenty of apps and scripts written [...]

Posted in Developer, python | Hits: 12331 | 1 Comment »

Reverse a string

          0 votos

October 9th, 2006 toydi

python provides a -c option to accept and run a script line.
To reverse a string like this one: “toydi deified idiot”.
echo ‘toydi deified idiot’ | python -c “print raw_input()[::-1]”

echo prints the string to stdout.
python run the script line.
raw_input() read from stdin (to read from pipe and return the string).
[::-1] simply says: steps through and [...]

Posted in python, rev | Hits: 7570 | 5 Comments »

writting executable script

          0 votos

October 8th, 2006 mysurface

Shell script (sh), Bash script (bash), Python and perl are all scripting language. By default, to run a scripting file, for example Python script, you need to do this:
python myscript.py
Another example for shell script:
sh myscript.sh
But we make is executable and can execute by running directly like this
./myscript.py
If you place your script into directory that exported [...]

Posted in Bash, Developer, chmod, file, python, sh, which | Hits: 12515 | 1 Comment »