Using cp command via RunProgram

Mac OSX specific forum
a.ross
User
User
Posts: 21
Joined: Tue Dec 08, 2009 12:50 am

Using cp command via RunProgram

Post 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?
spacebuddy
Enthusiast
Enthusiast
Posts: 356
Joined: Thu Jul 02, 2009 5:42 am

Re: Using cp command via RunProgram

Post 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$
a.ross
User
User
Posts: 21
Joined: Tue Dec 08, 2009 12:50 am

Re: Using cp command via RunProgram

Post 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.
a.ross
User
User
Posts: 21
Joined: Tue Dec 08, 2009 12:50 am

Re: Using cp command via RunProgram

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