# patch command display redirect to file?



## NOYB (Aug 12, 2012)

Title pretty much says it.

But how can the patch command display output, not the file patch output, be redirected or tee'd to a file.

I've tried piping to tee and redirection '>' but to no avail.  File gets created but is empty and output is on screen only.


----------



## UNIXgod (Aug 12, 2012)

Are you trying to output diff to a file?

`% diff -u file alteredfile > newfile.patch`


----------



## NOYB (Aug 12, 2012)

UNIXgod said:
			
		

> Are you trying to output diff to a file?
> 
> `% diff -u file alteredfile > newfile.patch`


 
No.

Want the displayed output of patch command (status of patches; success, ignored, etc.) redirected or tee'd to a file.  Not the patch itself.


----------



## wblock@ (Aug 13, 2012)

Please give a specific example.  Guessing (untested):
`% patch < patchfile.diff > /tmp/output.txt`


----------



## NOYB (Aug 13, 2012)

`$ patch -p0 -i patchfile`

Where patchfile is a unified diff

Want the "DISPLAYED OUTPUT", not the diff or patched file, either redirected or tee'd to a file.


----------



## phoenix (Aug 14, 2012)

Have you tried redirecting both stdout and stderr?

For sh-based shells:
`# patch -p0 -i patchfile > output.txt 2>$1`


----------



## NOYB (Aug 14, 2012)

phoenix said:
			
		

> Have you tried redirecting both stdout and stderr?
> 
> For sh-based shells:
> `# patch -p0 -i patchfile > output.txt 2>$1`


 
[cmd=:]patch -p0 -i patchfile > output.txt 2>$1
Ambiguous output redirect.
[/cmd]


----------



## izotov (Aug 14, 2012)

NOYB said:
			
		

> [cmd=:]patch -p0 -i patchfile > output.txt 2>$1
> Ambiguous output redirect.
> [/cmd]


This redirection syntax depends on your shell.
For example with sh(1) it is (*&* instead of $):
`% patch -p0 -i patchfile > output.txt 2>[b]&[/b]1`
If you are using csh(1)/tcsh(1) (which is quite probable on FreeBSD) then it is something completely different. Consult the manpages.


----------



## jalla (Aug 14, 2012)

```
patch < x.diff >& patch.log
```


----------



## NOYB (Aug 15, 2012)

jalla said:
			
		

> ```
> patch < x.diff >& patch.log
> ```


 
Thank you.  

Changed the redirection to a pipe to tee for screen and log file output.

patch -p0 -i unified_diff_file |& tee patch.log


----------

