* system command output different in guile than on command line [not found] <1155809260.1393834.1596576862334.ref@mail.yahoo.com> @ 2020-08-04 21:34 ` vapnik spaknik 2020-08-05 7:47 ` tomas 2020-08-05 11:27 ` vapnik spaknik via General Guile related discussions 0 siblings, 2 replies; 4+ messages in thread From: vapnik spaknik @ 2020-08-04 21:34 UTC (permalink / raw) To: guile users mailing list Hi, I'm trying to write some code to get the size of a diff of two files. If I run the following pipeline in my zsh shell: > diff -ua /tmp/file1 /tmp/file2 | wc -c it prints 215 However when I run the following in guile: guile> (system "diff -ua /tmp/file1 /tmp/file2 | wc -c") it prints 243. I've tried for other pairs of files, and the difference between the command line results and the guile results always seems to be 28. This is not too much of a problem in itself because I can just subtract 28 in my guile code, but it worries me; why the discrepancy? Are there other differences between guile system calls and the command line that I need to be aware of? Another strange thing is that if I use the pipeline procedure to do the same thing, then I get an exit code of 1 from the wc command, but it still returns the same result: (define (diffsize f1 f2) (receive (from to pids) (pipeline (list (list "/usr/bin/diff" "-ua" f1 f2) (list "/usr/bin/wc" "-c"))) (let ((rval (cons f2 (string->number (string-delete #\newline (read-delimited " " from))))) (xvals (map (compose status:exit-val cdr waitpid) pids))) (close to) (close from) (format #t "Exit values: ~a\n" xvals) rval))) guile> (diffsize "/tmp/file1" "/tmp/file2") Exit values: (0 1) ("/tmp/file2" . 243) Why? ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: system command output different in guile than on command line 2020-08-04 21:34 ` system command output different in guile than on command line vapnik spaknik @ 2020-08-05 7:47 ` tomas 2020-08-05 11:27 ` vapnik spaknik via General Guile related discussions 1 sibling, 0 replies; 4+ messages in thread From: tomas @ 2020-08-05 7:47 UTC (permalink / raw) To: guile-user [-- Attachment #1: Type: text/plain, Size: 868 bytes --] On Tue, Aug 04, 2020 at 09:34:22PM +0000, vapnik spaknik wrote: > Hi, > I'm trying to write some code to get the size of a diff of two files. > If I run the following pipeline in my zsh shell: > > > diff -ua /tmp/file1 /tmp/file2 | wc -c > > it prints 215 > However when I run the following in guile: > > guile> (system "diff -ua /tmp/file1 /tmp/file2 | wc -c") Have you actually tried to compare both results? There are a couple of things which could make a difference. The one which first comes to mind would be different environments (PATH, language settings in LANG, LC_). One thing you might want to try (to keep most of your experimental setup) would be: diff -ua /tmp/file1 /tmp/file2 > /tmp/delta1 and then guile> (system "diff -ua /tmp/file1 /tmp/file2 > /tmp/delta2") ...and then diff the diffs. Cheers -- t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: system command output different in guile than on command line 2020-08-04 21:34 ` system command output different in guile than on command line vapnik spaknik 2020-08-05 7:47 ` tomas @ 2020-08-05 11:27 ` vapnik spaknik via General Guile related discussions 2020-08-05 12:24 ` tomas 1 sibling, 1 reply; 4+ messages in thread From: vapnik spaknik via General Guile related discussions @ 2020-08-05 11:27 UTC (permalink / raw) To: guile users mailing list On Tuesday, August 4, 2020, 10:34:22 PM GMT+1, vapnik spaknik <vapniks@yahoo.com> wrote: >Hi, > I'm trying to write some code to get the size of a diff of two files. >If I run the following pipeline in my zsh shell: > >> diff -ua /tmp/file1 /tmp/file2 | wc -c > >it prints 215 >However when I run the following in guile: > >guile> (system "diff -ua /tmp/file1 /tmp/file2 | wc -c") > >it prints 243. OK... I was being stupid. The shell command that I actually ran was: diff -ua file1 file2 | wc -c i.e. without the directories in the paths since I was running from within /tmp This meant the command I ran in the shell was slightly different than the one ran in guile, and hence the difference in diffs. However, I'm still perplexed by the non-zero error code returned in the pipeline: >Another strange thing is that if I use the pipeline procedure to do the same thing, then I get an exit code of 1 >from the wc command, but it still returns the same result: >(define (diffsize f1 f2) > (receive (from to pids) > (pipeline (list (list "/usr/bin/diff" "-ua" f1 f2) > (list "/usr/bin/wc" "-c"))) > (let ((rval (cons f2 (string->number > (string-delete #\newline > (read-delimited " " from))))) > (xvals (map (compose status:exit-val cdr waitpid) pids))) > (close to) > (close from) > (format #t "Exit values: ~a\n" xvals) > rval))) > >guile> (diffsize "/tmp/file1" "/tmp/file2") >Exit values: (0 1) >("/tmp/file2" . 243) > >Why? ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: system command output different in guile than on command line 2020-08-05 11:27 ` vapnik spaknik via General Guile related discussions @ 2020-08-05 12:24 ` tomas 0 siblings, 0 replies; 4+ messages in thread From: tomas @ 2020-08-05 12:24 UTC (permalink / raw) To: vapnik spaknik; +Cc: guile users mailing list [-- Attachment #1: Type: text/plain, Size: 615 bytes --] On Wed, Aug 05, 2020 at 11:27:30AM +0000, vapnik spaknik via General Guile related discussions wrote: [...] > OK... I was being stupid. We all are, most of us more often than not ;-) >Another strange thing is that if I use the pipeline procedure to do the same thing, then I get an exit code of 1 >from the wc command, but it still returns the same result: This is by design. Quote the "diff" man page: "Exit status is 0 if inputs are the same, 1 if different, 2 if trouble." That's probably so that you can do things in the shell like diff a b > /dev/null && echo "same" || echo "diff" Cheers -- t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-05 12:24 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <1155809260.1393834.1596576862334.ref@mail.yahoo.com> 2020-08-04 21:34 ` system command output different in guile than on command line vapnik spaknik 2020-08-05 7:47 ` tomas 2020-08-05 11:27 ` vapnik spaknik via General Guile related discussions 2020-08-05 12:24 ` tomas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).