runcommand linux command in .exe crosscompiled program lazarus / 21-General ---------------------------------------------------------------------- toby · 2023-10-15 19:09 https://wiki.freepascal.org/Executing_External_Programs     says runcommand is cross platform if i compile this in linux - no problem writeln(runcommand('/bin/ls', s));     -> TRUE writeln(s);                            -> good ls output but crosscompiling into an .exe i don't even get FALSE from the writeln(runcommand  .... line is there a way to execute a linux command in a .exe windows fpc program?? ---------------------------------------------------------------------- Fibonacci · 2023-10-15 20:01 But does /bin/ls exists? How do you run this .exe under Linux? Wine? Or do you execute it under Windows? Then the path is incorrect. I have ls.exe on my Windows, and this works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   writeln('run = ', RunCommand('C:\msys32\usr\bin\ls', s));  writeln('s = ', s); ---------------------------------------------------------------------- toby · 2023-10-15 20:24 i am on a linux system (so /bin/ls exists) and i am using ppcrossx64 to cross compile to .exe then using wine64 to run it     wine x.exe i've tried using winecnsole but also get no output i used /bin/ls as a simple example - actually using /usr/local/bin/mpstat so want the linux output run from the runcommand in the .exe ---------------------------------------------------------------------- Fibonacci · 2023-10-15 20:52 Quotefunction RunCommand(const cmdline:TProcessString;out outputstring:string):boolean; deprecated; Deprecated + it uses TProcess I cant test on Linux now, but check if ExecuteProcess() from SysUtils works ---------------------------------------------------------------------- toby · 2023-10-15 21:28 thanks it works sysutils.executeprocess('/bin/ls', ''); but this is the exception output -- [FORMS.PP] ExceptionOccurred good directory listing   Sender=EOSError   Exception=Failed to execute ""/bin/ls"?", error code: 6   Stack trace:   $000000010004391B   $0000000100043614   $0000000100007167  main,  line 122 of sysmon.pas   $0000000100007F26   $000000010001A250   $0000000100002CE0   $00007FB5D03C41B1 Exception at 000000010004391B: EOSError: Failed to execute ""/bin/ls"?", error code: 6. -- i guess i'll have to pipe output to a file and trap the exception ?? sysutils.executeprocess('/bin/bash', '-c "/bin/ls > nn.txt.1"'); --- ---------------------------------------------------------------------- toby · 2023-10-15 22:05 6 Invalid file handle If this happens, the file variable you are using is trashed; it indicates that your memory is corrupted. trapping the exception and piping to a file (then reading file back in) seems 20% faster then using runcommand in pure linux but there is no exception with pure linux and no form transparency --- i guess i'm pushing the envelope here to get a transparnt form using color := clwhite; setwindowlongptr(self.handle, gwl_exstyle, getwindowlongptr(self.handle, gwl_exstyle) or ws_ex_layered); setlayeredwindowattributes(self.handle, clwhite, 0, lwa_colorkey); which requires compiling the lazarus form using windows unit using ppcrossx64 then using wine64 to run it ---------------------------------------------------------------------- Fibonacci · 2023-10-15 22:58 Quote from: toby on October 16, 2023, 12:05:25 ami guess i'm pushing the envelope here to get a transparnt form using color := clwhite; setwindowlongptr(self.handle, gwl_exstyle, getwindowlongptr(self.handle, gwl_exstyle) or ws_ex_layered); setlayeredwindowattributes(self.handle, clwhite, 0, lwa_colorkey); which requires compiling the lazarus form using windows unit using ppcrossx64 then using wine64 to run it For multiplatform form transparency, have a look here: https://forum.lazarus.freepascal.org/index.php/topic,64685.msg492087.h tml#msg492087 ---------------------------------------------------------------------- toby · 2023-10-15 23:10 thanks but i think that is just for making images/png etc transparent i am doing form transparency so just the tlabels are visible on the fluxbox screen ---------------------------------------------------------------------- marcov · 2023-10-16 12:45 Quote from: Fibonacci on October 15, 2023, 10:52:08 pmQuotefunction RunCommand(const cmdline:TProcessString;out outputstring:string):boolean; deprecated; Deprecated + it uses TProcess Only the "one commandline" versions are deprecated, the ones that separate parameters using open arrays are not. Tprocess currently has very few outstanding bugs, so I don't see how that is a problem. QuoteI cant test on Linux now, but check if ExecuteProcess() from SysUtils works It is fine, but typically doesn't pipe output and you have to resort to piping, which is not necessary in the RunCommand example ---------------------------------------------------------------------- toby · 2023-10-16 17:01 marcov said '... so I don't see how that is a problem.' except that it doesn't work in an .exe compiled with your ppcrossx86 and run from wine64 ---------------------------------------------------------------------- tetrastes · 2023-10-16 17:25 Quote from: toby on October 16, 2023, 01:10:08 amthanks but i think that is just for making images/png etc transparent i am doing form transparency so just the tlabels are visible on the fluxbox screen https://forum.lazarus.freepascal.org/index.php/topic,52056.0.html ---------------------------------------------------------------------- Fibonacci · 2023-10-16 18:11 Quote from: toby on October 16, 2023, 07:01:36 pmexcept that it doesn't work in an .exe compiled with your ppcrossx86 and run from wine64 Dont blame him, he has a short memory, he often only remembers the very last post he read Quote from: marcov on October 16, 2023, 02:45:09 pmTprocess currently has very few outstanding bugs, so I don't see how that is a problem. That I said because instead of trying with RunCommand, TProcess directly can be used, gives more options. I very quick checked ExecuteProcess() and it seemed to open a process in a different way. So thats working, but has problems with pipes. I have a theory why this wont work. Wine is simulating Windows, when you open a process Wine expectes it to be a valid Windows PE, so it fails. if this multiplatform solution eventually uses Windows API CreateProcess, because the target is Windows, it fails to open non- Windows executable. I guess running an app in Wine because you want form transparency is not a solution. Your question should be "how to make transparent form under Linux", not "runcommand doesnt work". ---------------------------------------------------------------------- marcov · 2023-10-16 19:17 Quote from: toby on October 16, 2023, 07:01:36 pm marcov said '... so I don't see how that is a problem.' except that it doesn't work in an .exe compiled with your ppcrossx86 and run from wine64 File a bug with Wine. ---------------------------------------------------------------------- toby · 2023-10-16 22:22 Fibonacci you said I guess running an app in Wine because you want form transparency is not a solution. Your question should be "how to make transparent form under Linux", not "runcommand doesnt work". i agree fully    i already tried https://forum.lazarus.freepascal.org/index.php/topic,64677.0.html you also said I have a theory why this wont work. Wine is simulating Windows, when you open a process Wine expectes it to be a valid Windows PE, so it fails. if this multiplatform solution eventually uses Windows API CreateProcess, because the target is Windows, it fails to open non- Windows executable. just a question doesn't sysutils.executeprocess run in wine also expect it to be a valide Windows PE (.exe)? your suggestion about trying sysutils.executeprocess with the exception trap and writing to a file is actually faster then using the runcommand in my linux trials - even if there is a created file and reading from a file there that isn't in the runcommand or tprocess using the multi line options. so even in my linux code i've switched over to using it - ... while awaiting the linux form transparency fix it is also speed up and easier code wise to parse the file lines then the resulting 'string' from runcommand so this worked out for the best --- tetrastes thanks - i had already found that forum posting https://forum.lazarus.freepascal.org/index.php/topic,52056.0.html https://forum.lazarus.freepascal.org/index.php/topic,52056.15.html but i didn't see any thing that i could use - the compton wouldn't even compile i realizeis that fluxbox is not a compositing wm - so i thought composite might be the problem - but following this https://wiki.archlinux.org/title/Xcompmgr    didn't help when i enabled  xcompmgr -c  the c++ program that uses snprintf to put the lines on the x11 fluxbox window 'disappeared' but was still there and when killing the  xcompmgr it was visible again (and it occasionally would flicker into view - i guess the composite took a lot of cpu) then when running the lazarus form with the alphablend code in it with the   xcompmgr -c  running the alphablend had no affect) but with   transset -n formname 0       the whole form would be affected even the tlabels (i thought maybe making each tlabel a form in a form might work but the coding got to crazy) same with the MSEgui transparent.zip program in the post - it only the whole form went transparent with transset so i went back to using the setwindowlongptr with windows unit (ppcrossx64 and wine64) which works while the alphablend with  xcompmgr -c  fails --- marcov isn't the exception coming from fpc and not wine? --- ---------------------------------------------------------------------- marcov · 2023-10-17 06:49 Quote from: toby on October 17, 2023, 12:22:36 ammarcov isn't the exception coming from fpc and not wine? Yes. It raises an exception when the OS call comes back . Executeprocess was original only meant to have some execution ability in the core system (compiler+RTL), for testsuite, buildtools and other helpers. It was supposed to remove the need for a lot of OS specific ifdefed code in those places. TProcess was packages, and not as far developed back then (specially across applications).  Runcommand came later because i noticed that too many people used the simple TProcess scenario of piping in the wiki and then got stuck if the output was longer than expected.  Runcommand is nothing but a (set of ) utility functions to fixate and distribute some best TProcess practices. As for the original topic, there used to be also wine in library form. Maybe that allows easier mixing and matching of win32 guest and *nix host functions