[4.20] Bug or Problem code ?
-
- Enthusiast
- Posts: 468
- Joined: Sat Dec 20, 2003 6:19 pm
- Location: Switzerland
Not very nice (not for unicode and no error-checking), but for the
meantime, it could be useful
meantime, it could be useful

Code: Select all
program.s = "pbcompiler"
p = popen_("/usr/bin/which " + program, "r")
buffer.s = Space(256)
out.s = ""
While Not feof_(p)
n = fread_(@buffer, 1, 256, p)
PokeC(@buffer + n * SizeOf(character), 0)
out + buffer
Wend
pclose_(p)
Debug Len(out)
Debug out
Athlon64 3700+, 1024MB Ram, Radeon X1600
GUI Shortcut !flaith wrote:How do you run Purebasic : By a batch or by a GUI Shortcut ?
remi_meier wrote:Not very nice (not for unicode and no error-checking), but for the
meantime, it could be useful![]()
Code: Select all
program.s = "pbcompiler" p = popen_("/usr/bin/which " + program, "r") buffer.s = Space(256) out.s = "" While Not feof_(p) n = fread_(@buffer, 1, 256, p) PokeC(@buffer + n * SizeOf(Character), 0) out + buffer Wend pclose_(p) Debug Len(out) Debug out
I have a simple return (0 + empty string) but if i make /usr/bin/which pbcompiler, i have the goof path of pbcompiler.
Not Unicode !
-
- Enthusiast
- Posts: 468
- Joined: Sat Dec 20, 2003 6:19 pm
- Location: Switzerland

Could you try
Code: Select all
which which
Code: Select all
update-alternatives --list which
Perhaps there is a different which interfering?
Is there a shell that implements "which" on its own?
Or does it work with different programs? Like "ls" or "man"?
Athlon64 3700+, 1024MB Ram, Radeon X1600
For the "which which" :
And the "update-alternatives --list which" :
And any others which :
Code: Select all
franklin@novatux-laptop:~$ which which
/usr/bin/which
Code: Select all
franklin@novatux-laptop:~$ update-alternatives --list which
Pas d'alternatives pour which.
Code: Select all
franklin@novatux-laptop:~$ which ls
/bin/ls
franklin@novatux-laptop:~$ which man
/usr/bin/man
This code works for me. (PB 4.30 beta4, should work with earlier versions too though).Progi1984 wrote:I tried this code :And Sortie$ returns ""Code: Select all
Compilateur = RunProgram("which", "pbcompiler ", "", #PB_Program_Open|#PB_Program_Read) Sortie$ = "" If Compilateur While ProgramRunning(Compilateur) Sortie$ + ReadProgramString(Compilateur) + Chr(13) Wend Sortie$ + Chr(13) + Chr(13) Sortie$ + "Code de retour : " + Str(ProgramExitCode(Compilateur)) EndIf MessageRequester("Sortie", Sortie$)
I think your problem is that the PATH variable is different for the PB program and your console tests. (maybe you add the PB location to PATH in .bashrc, in which case the GUI shortcut does not get this).
What exitcode do you get when running this ? (0 means the target was found, nonzero means that which could not find a file with this name in PATH)
If which cannot find the file, then the error line is printed on stderr, which means that you need #PB_Program_Error and ReadProgramError() to read that. It won't show up in the normal output. The simplest is just to check ProgramExitCode() and if it is not 0 then the file was simply not found.
Try this from PB and the shell and compare the result:
Code: Select all
Debug GetEnvironmentVariable("PATH")
Code: Select all
echo $PATH
Something like this:
Code: Select all
If system_("which bash >/tmp/which_test.txt 2>/dev/null") = 0
If ReadFile(0, "/tmp/which_test.txt")
Debug ReadString(0)
CloseFile(0)
Else
Debug "-- cannot read output file --"
EndIf
Else
Debug "-- calling which failed or target file not found --"
EndIf
DeleteFile("/tmp/which_test.txt")
quidquid Latine dictum sit altum videtur
Code: Select all
Compilateur = RunProgram("which", "pbcompiler ", "", #PB_Program_Open|#PB_Program_Read)
Sortie$ = ""
If Compilateur
While ProgramRunning(Compilateur)
Sortie$ + ReadProgramString(Compilateur) + Chr(13)
Wend
Sortie$ + Chr(13) + Chr(13)
Sortie$ + "Code de retour : " + Str(ProgramExitCode(Compilateur))
EndIf
MessageRequester("Sortie", Sortie$)
Code: Select all
Debug GetEnvironmentVariable("PATH")
Code: Select all
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Code: Select all
echo $PATH
Code: Select all
franklin@novatux-laptop:~$ echo $PATH
/media/DISK/Programs/purebasic/compilers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Code: Select all
#purebasic
export PUREBASIC_HOME=/media/DISK/Programs/purebasic
export PATH=$PUREBASIC_HOME/compilers:$PATH
Code: Select all
If system_("which bash >/tmp/which_test.txt 2>/dev/null") = 0
If ReadFile(0, "/tmp/which_test.txt")
Debug ReadString(0)
CloseFile(0)
Else
Debug "-- cannot read output file --"
EndIf
Else
Debug "-- calling which failed or target file not found --"
EndIf
DeleteFile("/tmp/which_test.txt")
Code: Select all
If system_("which pbcompiler >/tmp/which_test.txt 2>/dev/null") = 0
If ReadFile(0, "/tmp/which_test.txt")
Debug ReadString(0)
CloseFile(0)
Else
Debug "-- cannot read output file --"
EndIf
Else
Debug "-- calling which failed or target file not found --"
EndIf
DeleteFile("/tmp/which_test.txt")
Which error do I have ?
And how can I solve it ?
> Which error do I have ?
Well, your code has no error. The returnvalue of 1 tells you that which simply could not find the PureBasic compiler.
The .bashrc setting only affects the console, not the GUI-started PureBasic IDE. Try to compile the code to an executable and run it from the console. This should show the result you expect.
> And how can I solve it ?
You just have to be prepared for the fact that which may not find the purebasic path. (either because your program is run from the GUI, or because the user never added purebasic to the path anywhere)
If the exitcode is not 0, just tell the user that PureBasic was not found and offer a way to enter the path manually. Thats all you can do.
Well, your code has no error. The returnvalue of 1 tells you that which simply could not find the PureBasic compiler.
The .bashrc setting only affects the console, not the GUI-started PureBasic IDE. Try to compile the code to an executable and run it from the console. This should show the result you expect.
> And how can I solve it ?
You just have to be prepared for the fact that which may not find the purebasic path. (either because your program is run from the GUI, or because the user never added purebasic to the path anywhere)
If the exitcode is not 0, just tell the user that PureBasic was not found and offer a way to enter the path manually. Thats all you can do.
quidquid Latine dictum sit altum videtur
Affirmative, thanks for your answer et explanationsfreak wrote:> Which error do I have ?
Well, your code has no error. The returnvalue of 1 tells you that which simply could not find the PureBasic compiler.
The .bashrc setting only affects the console, not the GUI-started PureBasic IDE. Try to compile the code to an executable and run it from the console. This should show the result you expect.
> And how can I solve it ?
You just have to be prepared for the fact that which may not find the purebasic path. (either because your program is run from the GUI, or because the user never added purebasic to the path anywhere)
If the exitcode is not 0, just tell the user that PureBasic was not found and offer a way to enter the path manually. Thats all you can do.
