Page 1 of 1

Using cp command via RunProgram

Posted: Thu Mar 08, 2012 11:09 pm
by a.ross
I had a quick look but couldn't find a suitable answer on the forums...
When ever I run the cp command via runprogram using the following code it runs correctly, but only if i dont have any spaces in what i'm copying:

Code: Select all

from$=OpenFileRequester("Select file","","",1)
too$=PathRequester("choose dest", "")
from$=ReplaceString(from$," ","\ ")
too$=ReplaceString(too$," ","\ ")
run=RunProgram("cp","-v "+From$+" "+too$,"",#PB_Program_Open|#PB_Program_Read)
While ProgramRunning(run)
  out$+ReadProgramString(run)+Chr(13)
Wend
CloseProgram(run)
OpenFile(1,"/Users/images/Desktop/Basic/output.txt")
WriteString(1,From$+" "+too$)
CloseFile(1)
MessageRequester("answer",Str(run)+" "+out$+": "+from$+" : "+too$,#PB_MessageRequester_Ok)

Now I'm converting spaces in the string with "\ ", and if I copy the command sent to cp using runprogram from my output.txt file to terminal it copies fine, so the syntax seem right.
Also if theres a space in the command line i get no response from #programoutput, If theres no space I get what i would expect to see in terminal....
Anyone know whats going on?

Re: Using cp command via RunProgram

Posted: Fri Mar 09, 2012 7:54 am
by spacebuddy
a.ross wrote:I had a quick look but couldn't find a suitable answer on the forums...
When ever I run the cp command via runprogram using the following code it runs correctly, but only if i dont have any spaces in what i'm copying:

Code: Select all

from$=OpenFileRequester("Select file","","",1)
too$=PathRequester("choose dest", "")
from$=ReplaceString(from$," ","\ ")
too$=ReplaceString(too$," ","\ ")
run=RunProgram("cp","-v "+From$+" "+too$,"",#PB_Program_Open|#PB_Program_Read)
While ProgramRunning(run)
  out$+ReadProgramString(run)+Chr(13)
Wend
CloseProgram(run)
OpenFile(1,"/Users/images/Desktop/Basic/output.txt")
WriteString(1,From$+" "+too$)
CloseFile(1)
MessageRequester("answer",Str(run)+" "+out$+": "+from$+" : "+too$,#PB_MessageRequester_Ok)

Now I'm converting spaces in the string with "\ ", and if I copy the command sent to cp using runprogram from my output.txt file to terminal it copies fine, so the syntax seem right.
Also if theres a space in the command line i get no response from #programoutput, If theres no space I get what i would expect to see in terminal....
Anyone know whats going on?

You need to put quotes, like this.

run=RunProgram("cp","-v "+chr(34)+From$+chr(34)+" "+chr(34)+too$+chr(34),"",#PB_Program_Open|#PB_Program_Read)

that should now work if you have spaces in From$ or too$

Re: Using cp command via RunProgram

Posted: Sat Mar 10, 2012 2:24 am
by a.ross
Hmmmm, I'm sure I tried that first, coming from a windows enviroment where you need to do that to encapsulate spaces, would i still need to have the "/ " in there as well?
Ie "users\images\desktop\this/ folder"
Ps I'm programming on a work computer as i don't own a Mac myself so cant test it till after the weekend.

Re: Using cp command via RunProgram

Posted: Sun Mar 11, 2012 11:07 pm
by a.ross
I can't believeI it! was using chr(32)! so I had been adding a space instead of speachmarks :oops:

Thanks spacebuddy, been using ascii for over 20 years since my ZX and I made such a simple mistake