LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-12-2015, 02:09 AM   #1
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102
Blog Entries: 1

Rep: Reputation: Disabled
Unhappy diff command reports 256 error value instead of success and failure results


Hi All,

When I run a script in perl, something like below: I`m stuck up in the error result as 256. Appreciate the solution for the below script
using:sunOS 5.10
Quote:
my $result = system("diff Tmp_IcdGenFile_log.c Tmp_DumpFile_log.c");
 
Old 06-12-2015, 04:13 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
looks like it is a perl script, isn't it?
http://perldoc.perl.org/functions/system.html
 
Old 06-12-2015, 04:23 AM   #3
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Yes, it is perl script..the question is simple,I just want to know whether both files are same or not.

is there any other way to know this with diff ? (or) in any alternate way ?

Last edited by rpittala; 06-12-2015 at 05:16 AM.
 
Old 06-12-2015, 05:44 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
so read the page I sent you, how should you check the result:
Code:
 printf "child exited with value d\n", $? >> 8;
but in case of small files you can read them into variables and you only need to compare to variables inside perl.
http://www.perlhowto.com/read_the_co...nto_a_variable
 
Old 06-12-2015, 06:44 AM   #5
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
yes, I had gone through the link provided by you and the child exit status 1 after >>8.

The return value of the system command for "diff" is not as expected and even I tried the system command for "cmp".

Finally, I need to copy the differ files(ignoring the comment sections) to other locations

below is code:
FYI..
working on sunOS 5.10-->"diff -q" command won`t work for us

Quote:
system("cp $F_GPath Tmp_IcdGenFile_o_log.c");
system("cp $F_DPath Tmp_DumpFile_n_log.c");
system("cpp -p -fpreprocessed Tmp_IcdGenFile_o_log.c > Tmp_IcdGenFile_log.c");

system("cpp -p -fpreprocessed Tmp_DumpFile_n_log.c > Tmp_DumpFile_log.c");

if(system("diff Tmp_IcdGenFile_log.c Tmp_DumpFile_log.c") == 0) {
print "There is no difference in the file $F_DPath\n";
}#-b option added to ignore whitespace --ignore-matching-lines='^#'
elsif($? == 1) {
print "yes, there is a difference in the file $F_DPath\n";
 
Old 06-12-2015, 06:50 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
please read the manual of waitpid(2) especially the meaning of 'status' parameter
 
Old 06-12-2015, 07:18 AM   #7
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Basically, I`m an embedded professional. So, I`m aware of the system calls being used for.
Surprised to see the return values of the system call for diff in perl.

Actually, what the "system("diff file1 file2")" should return in general(I suppose in perl)?
 
Old 06-12-2015, 07:42 AM   #8
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Now, I understood the issue.

Some how when I do cpp -p -fpreprocessed -E Tmp_IcdGenFile.c >log.txt ..etc to remove the comments in a file.

The file name along with the line numnber(i.e., ex# 44 Tmp_IcdGenFile_o_log.c) is being appended twice in the log file and when I take the diff of the generated two log files.
The out put of the diff is always different(as the line number and the file names are always different).

Now, the question comes here is, how to avoid the appending file name and line number while generating the log files ?

As we know during the processing stage the comments are ignored and hence the approach is being implemented.

I would have used "cc -E file". But, because of some version issues of the compiler trying to run the command in cpp.
 
Old 06-12-2015, 08:29 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
What is the actual problem you want to solve? What is your goal?
 
Old 06-13-2015, 12:28 AM   #10
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
My actual goal is simple:

1)need to ignore the comments in two files located in different paths(say ../home/rajesh/core/modified.c and /home/rajesh/modified.c)
-> if we edit one file(say /home/rajesh/modified.c file) in the comment section we need to considered it as no change to the file and if we change in other places need to consider it as a change in the file
2)If it is a change in the file as per the above conditions, the file need to be moved to other location (i.e., by renaming the older(mv /home/rajesh/core/modified.c /home/rajesh/core/modified_old.c) file and copy the changed file to the location(cp /home/rajesh/modified.c /home/rajesh/core/modified.c))

and I`m stuck @ removing the comment from the .c file(as it is appending the file name and line number in the file) result in always a change in the file while taking the diff.

Hope this will help you to understand the issue here.

Last edited by rpittala; 06-13-2015 at 04:19 AM.
 
Old 06-13-2015, 02:33 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
And what if you change eight spaces to a Tab? Do you consider that different?

Maybe you should create Assembly source from both files (cc -S) and compare those.

And forget perl. That's what shell scripts are meant for.
 
Old 06-13-2015, 04:15 AM   #12
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Yes, even a single space is under consideration.
 
Old 06-15-2015, 05:58 AM   #13
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Hi Folks,

Thanks for the support.

I`m able to take the diff now by just simply removing the matched string in the file
Quote:
system("cpp -p -fpreprocessed Tmp_DumpFile_n_log.c | grep -v 'Tmp_DumpFile_n_log.c' > Tmp_DumpFile_log.c");
Just did this
 
Old 06-17-2015, 08:06 AM   #14
rpittala
Member
 
Registered: Jan 2012
Location: PUNE
Distribution: SunOS sun4v sparc sun4v Solaris
Posts: 102

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
and this works as well, simple command and no more line markers. We should be able to get the clean c code with out comments
Quote:
gcc -p -fpreprocessed -dD -E file.c
 
  


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
Command exit status 'success' and 'failure' thomas2004ch Solaris / OpenSolaris 4 07-03-2013 04:25 PM
Voice logger boot failure-reports 'error reading block 33051' sheyipetr Fedora 1 01-18-2011 02:14 AM
voice logger boot failure - reports 'error reading block 33051' sheyipetr Fedora 1 01-18-2011 02:13 AM
Success/failure reports installing Windows 7 beta in VirtualBox on Slackware 12.2 ? Didier Spaier Slackware 8 03-27-2009 04:46 AM
whats the command that reports program success? slinky2004 Linux - Newbie 2 07-10-2006 01:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:49 AM.

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