[solved]How to run more complex comandline using RunProgram?

Linux specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

[solved]How to run more complex comandline using RunProgram?

Post 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
Last edited by Kukulkan on Mon Aug 24, 2015 7:12 am, edited 1 time in total.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How to run a more complex comandline using RunProgram?

Post 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
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: How to run a more complex comandline using RunProgram?

Post 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
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How to run a more complex comandline using RunProgram?

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: How to run a more complex comandline using RunProgram?

Post 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)
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: How to run a more complex comandline using RunProgram?

Post 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
Post Reply