Using bash commands from PB?
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Using bash commands from PB?
Is it possible to issue a bash command from pb and get a return? For example, is there a way to get a current directory using 'pwd' and get a return of '/home/john' ?
If there is I would really like to know how. I could use that kind of function often.
Thanks,
John
If there is I would really like to know how. I could use that kind of function often.
Thanks,
John
John R. Duchek
St. Louis,MO
St. Louis,MO
Re: Using bash commands from PB?
Something like this?John Duchek wrote:Is it possible to issue a bash command from pb and get a return? For example, is there a way to get a current directory using 'pwd' and get a return of '/home/john' ?
If there is I would really like to know how. I could use that kind of function often.
Thanks,
John
Code: Select all
*MemoryID = AllocateMemory(100)
pwd = RunProgram("pwd","",GetCurrentDirectory(),#PB_Program_Open|#PB_Program_Read)
ReadProgramData(pwd,*MemoryID,100)
Debug PeekS(*MemoryID,-1,#PB_Ascii)
Re: Using bash commands from PB?
out of curiosity, any reason why you chose ReadProgramData over ReadProgramString? Since -String does not make you mess with buffers, peeks and formats/encodings, it seems to me to be the safer method. am I wrong?
Re: Using bash commands from PB?
Because nobody expects the Spanish inquisition!broozar wrote:out of curiosity, any reason why you chose ReadProgramData over ReadProgramString? Since -String does not make you mess with buffers, peeks and formats/encodings, it seems to me to be the safer method. am I wrong?
That "safer" method can cost you some time and nerves if there is an ambiguous output of the program whose output you expect. So, IMO, it is definitely much safer to use "Data" method, since it will either work as its "String" function, or actually produce proper results when needed. And it really isn't so hard to use, is ti?
Re: Using bash commands from PB?
Aren't Linux programs able to output Unicode characters to the console? Or is the console output UTF8?bbanelli wrote:Code: Select all
*MemoryID = AllocateMemory(100) pwd = RunProgram("pwd","",GetCurrentDirectory(),#PB_Program_Open|#PB_Program_Read) ReadProgramData(pwd,*MemoryID,100) Debug PeekS(*MemoryID,-1,#PB_Ascii)
Re: Using bash commands from PB?
To be honest, I wasn't paying much attention, but you are probably right, it should.Danilo wrote:Aren't Linux programs able to output Unicode characters to the console? Or is the console output UTF8?bbanelli wrote:Code: Select all
*MemoryID = AllocateMemory(100) pwd = RunProgram("pwd","",GetCurrentDirectory(),#PB_Program_Open|#PB_Program_Read) ReadProgramData(pwd,*MemoryID,100) Debug PeekS(*MemoryID,-1,#PB_Ascii)
Code: Select all
bubba@ubuntu-x86:~$ echo $LANG
en_US.UTF-8
Code: Select all
*MemoryID = AllocateMemory(100)
pwd = RunProgram("pwd","",GetCurrentDirectory(),#PB_Program_Open|#PB_Program_Read)
ReadProgramData(pwd,*MemoryID,100)
Debug "No flag: " + PeekS(*MemoryID,-1)
Debug "ASCII flag: " + PeekS(*MemoryID,-1, #PB_Ascii)
Debug "UTF-8 flag: " + PeekS(*MemoryID,-1, #PB_UTF8)
Re: Using bash commands from PB?
now who said it was safer i made the comment because i noticed that my output of "999" was returning nonsense when using Data+PeekI (result: funny long row of numbers), then i tried Data+PeekS with no format parameter (result: empty string), then Data+PeekS with UTF8 (proper result), so then I thought "... hang on a minute, why not use -String to begin with?", and that's how it came about.
do you think it is required/a good idea to parse the LANG env variable before interpreting the output, so you can set Ascii or UTF8 before using PeekS?
do you think it is required/a good idea to parse the LANG env variable before interpreting the output, so you can set Ascii or UTF8 before using PeekS?
Re: Using bash commands from PB?
Is a good idea, but "normally", linux use only utf-8!broozar wrote:do you think it is required/a good idea to parse the LANG env variable before interpreting the output, so you can set Ascii or UTF8 before using PeekS?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Re: Using bash commands from PB?
Someone will probably correct me if I'm wrong, but stdin, stdout and stderr are always FILE pointer types in return value. I think you cannot expect PeekI to return proper value in that case.broozar wrote:now who said it was safer i made the comment because i noticed that my output of "999" was returning nonsense when using Data+PeekI
Question prior to this would be is $LANG variable defined standard in all Linux console environments?do you think it is required/a good idea to parse the LANG env variable before interpreting the output, so you can set Ascii or UTF8 before using PeekS?
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: Using bash commands from PB?
Thank you all for the discussion. The code works great. However, I don't understand parts of it.
Is there someplace where this approach is discussed so I could read more about it?
Thanks,
John
Is there someplace where this approach is discussed so I could read more about it?
Thanks,
John
John R. Duchek
St. Louis,MO
St. Louis,MO
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: Using bash commands from PB?
Never mind...I found what I needed. I was not aware of the RunProgram(). slick.
Again, thanks,
John
Again, thanks,
John
John R. Duchek
St. Louis,MO
St. Louis,MO