Page 1 of 1
[solved]How to run more complex comandline using RunProgram?
Posted: Thu Aug 20, 2015 5:29 pm
by Kukulkan
Hello,
I like to run the following shell comandline using RunProgram:
Code: Select all
for i in *.pnm ; do convert "$i" "${i%.*}.jpg" ; done
I tried like this:
Code: Select all
Protected Foldername.s = "/tmp/images/"
Protected Convert.s = "for i in *.pnm ; do convert "+Chr(34)+"$i"+Chr(34)+" "+Chr(34)+"${i%.*}.jpg"+Chr(34)+" ; done"
RunProgram(Convert.s, "", Foldername.s, #PB_Program_Wait)
Sadly, this does not work.
I don't like to save a .sh file and I don't like to develop this in PureBasic (looping files) as Linux is doing a fine job here.
Any hint?
Kind Regards,
Kukulkan
Re: How to run a more complex comandline using RunProgram?
Posted: Thu Aug 20, 2015 8:22 pm
by Vera
Hello Kukulkan,
I don't know how several comandlines could be passed on via RunProgram() but maybe doing it in a way like this can be an option/idea for you:
Code: Select all
path.s ="/home/user/path/to/convertIMG/"
files.s = OpenFileRequester("title", path, "All png (*.png)|*.png", 0, #PB_Requester_MultiSelection)
; SetCurrentDirectory(path) ; could be used when WorkingDirectory$ should stay empty
While files
file$ = GetFilePart(files)
name$ = RemoveString(file$, ".png") + ".jpg"
para$ = file$ + " " + name$ ; or useing: +Chr(32)+
RunProgram("convert", para$, path, #PB_Program_Wait)
; RunProgram("convert", file$ +Chr(32)+ name$, path, #PB_Program_Wait) ; alternativ
files = NextSelectedFileName()
Wend
ps: thanks for introducing me to 'convert' - I had no idea it exists
greets ~ Vera
Re: How to run a more complex comandline using RunProgram?
Posted: Fri Aug 21, 2015 6:56 am
by Kukulkan
Hi Vera,
thank you, but this is exactly what I don't want to do (loop in PB). But I'm afraid that this is the only way to do...
Kukulkan
Re: How to run a more complex comandline using RunProgram?
Posted: Sun Aug 23, 2015 2:40 pm
by Vera
You're welcome
I wasn't sure if it was more addressed to the moving and renaming.
However, may I ask why you wouldn't want to create a temporary *.sh in the images' directory?
Is it that the scripts won't run alike on different distributions or maybe in foresight to prevent potential virus-alarms by scanners who dislike apps creating script files?
Just wondering what a reason could be. ~ Vera
Re: How to run a more complex comandline using RunProgram?
Posted: Sun Aug 23, 2015 3:06 pm
by Trond
RunProgram() only runs a program directly, it's completely unrelated to the shell (which is a separate program that you give commands to, that happens to also be able to run programs, in addition to lots of other stuff, like looping).
You need to put the name of the shell executable as the first parameter. Then write your command (this is like typing it in a terminal):
Code: Select all
Program = RunProgram("/bin/bash", "", "", #PB_Program_Write | #PB_Program_Open)
WriteProgramString(Program, "touch /home/trond/touched.delme", #PB_Ascii)
CloseProgram(Program)
Re: How to run a more complex comandline using RunProgram?
Posted: Mon Aug 24, 2015 7:11 am
by Kukulkan
Hello Vera, Trond,
thank you for the tip's and suggestions. I now will do the loop in PB. I thought I can simply execute such a script but Trond is right, it just runs an executable and not shell scripts. Maybe it is possible to run the shell interpreter with some given script in such a call, but never mind.
Vera, it was also kind of a general question. It would be possible to create/execute/delete a .sh script but I wanted to know if I can run such script using RunProgram() in general

Would be much simpler.
Kukulkan