Linux.com

Home Linux Community Forums Software Command Line About linux redirection

About linux redirection

Link to this post 12 Oct 10

hi,

i have a bit basic question about Linux redirectors. i have used them on command lines. e.g. command > file.txt

but how can i use them in programs, because they normally end up on the monitor.

All replies welcome :)

Link to this post 19 Oct 10

I'm not sure I follow. Are you asking how you use them when writing a script, when writing a program (e.g. in an open() call), or as a parameter inside of another application.

In a shell script, you would use them just like you are used to in the CLI.
In a program or a scripting language, you would also use them in the open() call aspart of the parameter, if the language you are using supports doing so, but this is often superfluos, since you can direct open() to opena file for reading or writing.
Inside another application as a parameter, it would depend completely on how the appliation was written. A security-minded prorgammer (*cough* a good programmer *cough*) would sanitize input from the user and strip out characters like < and > to prevent the user from using the application in unexpected or mischievous ways.

what is your specific use-case?

Link to this post 30 Oct 10

yes writing them in script actually, for e.g. in bash scripting or some other scripting language like php etc.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board