mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2021-10-04, 16:54   #12
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

22·34·31 Posts
Default

Quote:
Originally Posted by kruoli View Post
Are you piping something into the script? Or are you accessing stdin at any place in the script?
I don't personally do any BASH scripting. Everything is Perl...

But I have found that strace can be ***very*** helpful in figuring out what's going on in complex situations like this. Not easy to work with, but it /should/ give you everything you need to know about what's actually going on.
chalsall is offline   Reply With Quote
Old 2021-10-04, 17:36   #13
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2·7·281 Posts
Default

Attach the script for us to debug. Specify which arguments you might be using with the script.

paulunderwood is offline   Reply With Quote
Old 2021-10-04, 17:50   #14
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Attach the script for us to debug. Specify which arguments you might be using with the script.

Actually, I just wrote a small script that displays the exact behavior between working and not, by un/commenting two lines. The problem is definitely generated globally for the script, by reading a file:
Code:
#!/bin/bash

a="31363920 948583258055568 -21094061301960794201597 -101781123694367174730692456309 1859252514529139843616145918243322920 1347307311985305327578340438707291179185984 951738172269489471300643 -167704995415343890580296180142353038"
echo "$a" > testcase
#exec < "testcase"
#read b
c="31363920"
d="${a:0:8}"
e="${b:0:8}"
m="3"

echo "m is $m and d is $d and c is $c and b is ${b:0:10}... and a is ${a:0:10}..."
printf "\nYAFU says $c*$m is "
../../yafu/yafu "expr($c*$m)" -silent
printf "\nYAFU says $d*$m is "
../../yafu/yafu "expr($d*$m)" -silent
printf "\nYAFU says $e*$m is "
../../yafu/yafu "expr($e*$m)" -silent
With the lines commented out:
Code:
m is 3 and d is 31363920 and c is 31363920 and b is ... and a is 31363920 9...

YAFU says 31363920*3 is 94091760

YAFU says 31363920*3 is 94091760

YAFU says *3 is wrong number of arguments in *, expected 2
0
This is exactly what should result. But, here's an example of failure (commented lines uncommented):
Code:
m is 3 and d is 31363920 and c is 31363920 and b is 31363920 9... and a is 31363920 9...

YAFU says 31363920*3 is no variable indicator (@): interpreting batchfile lines as input expressions
eof; done processing batchfile

YAFU says 31363920*3 is no variable indicator (@): interpreting batchfile lines as input expressions
eof; done processing batchfile

YAFU says 31363920*3 is no variable indicator (@): interpreting batchfile lines as input expressions
eof; done processing batchfile
Note that the file read caused a failure for all YAFU instances.
EdH is offline   Reply With Quote
Old 2021-10-04, 17:53   #15
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default

Quote:
Originally Posted by chalsall View Post
I don't personally do any BASH scripting. Everything is Perl...

But I have found that strace can be ***very*** helpful in figuring out what's going on in complex situations like this. Not easy to work with, but it /should/ give you everything you need to know about what's actually going on.
I've tried to use strace in the past and would need to be more familiar with it for any successful results. It might come to that.

Last fiddled with by EdH on 2021-10-04 at 18:01 Reason: I just hate leaving out words, even little ones!
EdH is offline   Reply With Quote
Old 2021-10-04, 18:12   #16
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

10111111102 Posts
Default

Quote:
Originally Posted by EdH View Post
The problem is definitely generated globally for the script, by reading a file.
Ah! This definitely matches what I got from reading the code. Since you are reading from a file, isatty is 0. But since the file is read until the end, YAFU cannot extract any more lines, ignores the command line since it does not contain an @ and simply exits. The problem is that YAFU will always work that way when a piped input file is detected.

It is not a problem of bash, it only passes the information of not being connected to stdin to the YAFU process.

You could work around that by modifying driver.c according to my last post (e.g. commenting out the part where is_cmdlinerun gets set to 2 and instead inserting something like printf("WARNING: custom build, automatic stdin batch file detection disabled.\n"); to save you from running into the opposite problem in the future at some point.
kruoli is offline   Reply With Quote
Old 2021-10-04, 18:16   #17
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2·7·281 Posts
Default

Code:
am=3
c4=2346021463111956
      echo "c4 is $c4 and am is $am"
      c4m=$(echo "expr($c4*$am)")
      echo "c4 is $c4 and c4m is $c4m"
      c4m=$(factor $(expr $c4 \* $am))
      echo "c4 is $c4 and c4m is $c4m"
Works!
paulunderwood is offline   Reply With Quote
Old 2021-10-04, 18:31   #18
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default

Quote:
Originally Posted by kruoli View Post
Ah! This definitely matches what I got from reading the code. Since you are reading from a file, isatty is 0. But since the file is read until the end, YAFU cannot extract any more lines, ignores the command line since it does not contain an @ and simply exits. The problem is that YAFU will always work that way when a piped input file is detected.

It is not a problem of bash, it only passes the information of not being connected to stdin to the YAFU process.

You could work around that by modifying driver.c according to my last post (e.g. commenting out the part where is_cmdlinerun gets set to 2 and instead inserting something like printf("WARNING: custom build, automatic stdin batch file detection disabled.\n"); to save you from running into the opposite problem in the future at some point.
Ok, this is starting to make sense, then, since I'm trying to call YAFU while reading lines from an open file. You're saying YAFU is simply noting that a file is open, but not recognizing it is not a batchfile. I think the solution which I am now employing is my best option. I'm simply accepting the extra notes from YAFU and parsing out the wanted value. That way, I'm not changing anything in the YAFU code, that will be changed back with future pulls.

Thanks!
EdH is offline   Reply With Quote
Old 2021-10-04, 18:42   #19
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

100138 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Code:
am=3
c4=2346021463111956
      echo "c4 is $c4 and am is $am"
      c4m=$(echo "expr($c4*$am)")
      echo "c4 is $c4 and c4m is $c4m"
      c4m=$(factor $(expr $c4 \* $am))
      echo "c4 is $c4 and c4m is $c4m"
Works!
This doesn't work in the posted script:
Code:
YAFU says 31363920*3 is unrecognized variable or function 'factor94091760'
or:
Code:
YAFU says 31363920*3 is unrecognized character in input: -1
Thanks!
EdH is offline   Reply With Quote
Old 2021-10-04, 18:48   #20
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2×7×281 Posts
Default

Quote:
Originally Posted by EdH View Post
This doesn't work in the posted script:
Code:
YAFU says 31363920*3 is unrecognized variable or function 'factor94091760'
or:
Code:
YAFU says 31363920*3 is unrecognized character in input: -1
Thanks!
Of course not. I substituted ../../yafu/yafu with factor. You'll have to rectify it.
paulunderwood is offline   Reply With Quote
Old 2021-10-04, 21:07   #21
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3·372 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Of course not. I substituted ../../yafu/yafu with factor. You'll have to rectify it.
I'm missing something. I'm really tall, but somethings is just going right over my head.
EdH is offline   Reply With Quote
Old 2021-10-04, 21:16   #22
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2·7·281 Posts
Default

Here is what you should test:

Code:
am=3
c4=2346021463111956
      echo "c4 is $c4 and am is $am"
      c4m=$(echo "expr($c4*$am)")
      echo "c4 is $c4 and c4m is $c4m"
      c4m=$(../../yafu/yafu $(expr $c4 \* $am) -silent)
      echo "c4 is $c4 and c4m is $c4m"
Note the spaces around the operator \* in expr; They are important delimiters. Also note that * has to be escaped with \, otherwise it will be wildcard for files in the current directory.

Last fiddled with by paulunderwood on 2021-10-04 at 21:24
paulunderwood is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Startup Script Gerard Information & Answers 2 2018-11-01 08:40
Simple Script to get Trial Factoring Work jfamestad PrimeNet 3 2016-11-06 20:32
bash script for extracting primenet-status gLauss Linux 0 2010-07-31 11:19
Could you help me change this into a bash script? jasong Programming 1 2007-11-29 05:59
Help with Startup Script Proggie Software 1 2004-12-19 11:54

All times are UTC. The time now is 09:29.


Wed Dec 1 09:29:30 UTC 2021 up 131 days, 3:58, 1 user, load averages: 1.12, 1.25, 1.29

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.