Print the last error message from stderr?
If a program alone does write to stderr
you should be able to see its error output without the need for that helper function. In your post your command suggests you didn't use any redirection so you were supposed to see the error stream. To troubleshoot you of course could redirect both stdout
and stderr
to two separate files, (or both to the same one with &> file.txt
) and see what is going on actually
Related videos on Youtube
xrescom
Updated on September 18, 2022Comments
-
xrescom over 1 year
I created a script to measure distances between villages in the game Travian My code works correctly, but only with a specific partition. Because there is a fifth element with ($X1, $Y1, $X2, $Y2) which is the size of the map
Example: if all ($X1,$Y1,$X2,$Y2) numbers Less than 100 like ( 99 , 1 , -85 , -55 , 0 , 13 ... etc ) AND the map size is 200 (Max 200,-200) It works properly ..
This is the code:
<?php $distance = round(sqrt(pow(bcsub($X1, $X2,1),2)+pow(bcsub($Y1,$Y2,1),2)),1) ; ?>
==the result of== $X1 = 66 $Y1 = 55 $X2 = 44 $Y2 = 33 is (31.1)
But if the map size is 200 (Max 200,-200) and :-
- I choose a number greater than 100
- one of the numbers is negative
the result will be not correct
==the result of== $X1 = 101 $Y1 = 160 $X2 = 190 $Y2 = -194 is (365) And the correct one is (100.6)
http://travian.kirilloid.ru/distance.php#cc=101,160,190,-194&srv=1.45&size=200&spd=7&art=1
the point at (199, 199) is adjacent to (-199, -199) .. and the distance Between them is (4.2) .. in my code Gives me (562.9) ...
How do I solve this problem please :(
-
Charlie over 8 years
script.sh 2>error; tail -n 1 error; rm -f error;
? First redirecting errors to a file, then getting last line from that file, then deleting file. -
PHP Guru about 3 yearsI seem to remember this from basic algebra: a²+b²=c². In other words if you know x (the horizontal) and y (the vertical) you can compute the hypotenuse which is the distance between them. square root (x²+y²)=hypotenuse
-
Oliver M Grech about 3 years@PHP Guru: That's Pythagoras theorem. For this formula to work, angle of the shortest sides need to be 90 degrees
-
Oliver M Grech about 3 yearsWhat is the size of the map when your formula is correct?
-
PHP Guru about 3 yearsI assume the map is 2 dimensional? If it's round like the earth then it will not work. If it's 2 dimensional then you can operate on a cartesian coordinate system of x and y and pythagorean theorem works just fine.
-
xrescom about 3 yearsthe point at (199, 199) is adjacent to (-199, -199) .. and the distance Between them is (4.2) .. in my code Gives me (562.9) ...
-
xrescom about 3 yearsThank you, thank you, thank you ... the code works perfectly .