LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2020, 08:30 PM   #1
ge||ge
LQ Newbie
 
Registered: Dec 2015
Location: Austin
Distribution: Debian
Posts: 4

Rep: Reputation: Disabled
capture "gcc -v /dev/null.dev" to a file


Various forms of "cpp -v" to get the output into a file that I can edit have all failed.

I used [Search forums] from the Home page and got zero returns for cpp -v and for "cpp -v".

Assuming there is no rather simple answer to getting that, here is exactly what I hoped to get out of cpp -v which I can see on the console but cannot capture (except by using "script" which introduces additional problems).

Though I am baffled why various forms of "put the output into a file" fail, what got me off on to the "cpp -v" was the desire to know very specifically which c header files went into my compilation.

I am using Debian Linux 4.9.2-10 and gcc 4.9.2 (with some security updates).

Pointers about why my Search Forums failed for "cpp -v" may be illuminating.

Pointer about which forum for this kind of question is more appropriate in will help.

Last edited by ge||ge; 05-07-2020 at 08:37 PM. Reason: Had gcc on the brain, but question was for cpp.
 
Old 05-07-2020, 10:28 PM   #2
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ge||ge View Post
Various forms of "cpp -v" to get the output into a file that I can edit have all failed.
cpp isn't meant to be run standalone, and especially not without a filename, it will wait (forever) for the file data to come in through standard input. From the man page
Quote:
cpp
[-Dmacro[=defn]...] [-Umacro]
[-Idir...] [-iquotedir...]
[-Wwarn...]
[-M|-MM] [-MG] [-MF filename]
[-MP] [-MQ target...]
[-MT target...]
[-P] [-fno-working-directory]
[-x language] [-std=standard]
infile outfile
Note that infile and outfile arguments both are obligated. Another quote
Quote:
The C preprocessor is intended to be used only with C, C++, and Objective-C source
code. In the past, it has been abused as a general text processor. It will choke
on input which does not obey C's lexical rules.
So the input has to look a lot like C
 
1 members found this post helpful.
Old 05-08-2020, 03:56 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by ge||ge View Post
Various forms of "cpp -v" to get the output into a file that I can edit have all failed.
Pointers on what did you try exactly may help....
Pointers on what did you search exactly may help...
Pointers on what did you want to achieve at all may help...
 
Old 05-08-2020, 06:08 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ge||ge View Post
I used [Search forums] from the Home page and got zero returns for cpp -v and for "cpp -v".
I get many returns.

Quote:
here is exactly what I hoped to get out of cpp -v
Where?

To redirect output to a file, use the greater sign.
To redirect standard error to a file, use the double greater sign.
To redirect both, use one of these expressions:
Code:
cpp -v PARAMETERS > /tmp/file 2>&1
cpp -v PARAMETERS >& /tmp/file 
cpp -v PARAMETERS &> /tmp/file
 
Old 05-08-2020, 06:24 AM   #5
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by berndbausch View Post
To redirect output to a file, use the greater sign.
To redirect standard error to a file, use the double greater sign.
No, >> means: redirect stdout and APPEND to the file it redirects TO, so do not overwrite that
To redirect standard error you have to use 2> (redirect the "2" handle) in bash and sh-like shells. That's why 2>&1 works to redirect both: you redirect "2" to where "1" (stdout) is already going. That's why it has to be behind any redirection for 1 (the default is that both 1 and 2 go to the screen).

The standard file descriptors are
0 standard input (stdin), so used for < input redirection
1 standard output (stdout), so 1> is the same as just >
2 standard error (sterr), always needs an explicit 2
and from 3 on are free for the program code to use for files.

See the chapter "REDIRECTION" in the bash man page too.

Last edited by ehartman; 05-08-2020 at 06:26 AM.
 
Old 05-08-2020, 06:39 AM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ehartman View Post
No, >> means: redirect stdout and APPEND to the file it redirects TO,
Brain melt. Lack of sleep? Thanks for correcting me.
 
1 members found this post helpful.
Old 05-08-2020, 09:56 AM   #7
ge||ge
LQ Newbie
 
Registered: Dec 2015
Location: Austin
Distribution: Debian
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Pointers on what did you try exactly may help....
Pointers on what did you search exactly may help...
Pointers on what did you want to achieve at all may help...
This is the newbie forum. I tried not to put in so much information that it become TL;DR.

Search LinuxQuestions.org all forums using "cpp -v" or without the quotes. The zero (of less) results were what I thought I reported, but I am new to what I am expected to report.

In my 4th paragraph I thought I made it clear why I was at all interested in "cpp -v".
 
Old 05-08-2020, 10:32 AM   #8
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ge||ge View Post
This is the newbie forum. I tried not to put in so much information that it become TL;DR.
The L in TLDR means "little" in your case. It's hard to guess what you want.

I understand that you want to write the output of cpp -v in a file. If that is the case:
Code:
cpp -v >file 2>&1
does the trick.
 
Old 05-08-2020, 10:44 AM   #9
ge||ge
LQ Newbie
 
Registered: Dec 2015
Location: Austin
Distribution: Debian
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ehartman View Post
cpp isn't meant to be run standalone, and especially not without a filename, it will wait (forever) for the file data to come in through standard input. From the man page

Note that infile and outfile arguments both are obligated. Another quote

So the input has to look a lot like C
That infile outfile failed just as many other attempts did to get the output into a file.

What did work was to ignore the outfile requirement and use &>/tmp/a.
It did not occur to me that *all* that verbiage was an stderr response. In retrospect I have only seen short (1 or 2 lines) of stderr which I have generally had no interest in capturing. I suppose the "-v" also threw me off, but I guess one can have "verbose" stderr, too. I was using a suggestion from StackOverflow where it was shown (to someone several years ago) that cpp -v /dev/null /dev/null displayed what I wanted .... on the console screen. No one hinted that what was seen there was all known to be error output.

Though not impressed in my first forum outing here with the majority of replies, yours was the most informational, if not precisely an answer. I'm marking it SOLVED .. with a education to boot. Thanks.
 
Old 05-08-2020, 12:33 PM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by ge||ge View Post
This is the newbie forum. I tried not to put in so much information that it become TL;DR.

Search LinuxQuestions.org all forums using "cpp -v" or without the quotes. The zero (of less) results were what I thought I reported, but I am new to what I am expected to report.

In my 4th paragraph I thought I made it clear why I was at all interested in "cpp -v".
Actually you started with gcc -v which is not cpp -v. So that was a bit misleading for me. Fortunately others understood your post better.....
 
Old 05-10-2020, 06:27 PM   #11
ge||ge
LQ Newbie
 
Registered: Dec 2015
Location: Austin
Distribution: Debian
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Actually you started with gcc -v which is not cpp -v. So that was a bit misleading for me. Fortunately others understood your post better.....
I did make that error. As a newbie for LinuxQuestions I didn't "sit" on my preview. As you might nod at, I use gcc one heck of a lot more than cpp and have had questions (elsewhere) about gcc switches. I am surprised I caught my rather drastic error as fast as I did ... but not as fast as y'all did.

I would have guessed that most active LQ readers who ever post would let "newbie" questions percolate for a few hours (and let newer LQ members answer the rather easy "newbie" questions) before helping out.

I am impressed how quickly members are willing to help out.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Stopping cron job emails to root, do I use >/dev/null 2>&1 or &> /dev/null anon091 Linux - Newbie 3 11-12-2013 10:21 AM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 10:51 PM
1> /dev/null 2> /dev/null elyk Programming 9 09-20-2004 05:44 PM
CSH: "cmd >& file" or "cmd </dev/null >& file" stefanlasiewski Programming 1 09-08-2003 04:19 PM
1>/dev/null 2>/dev/null chr15t0 Linux - General 2 07-19-2002 08:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration