It is currently Tue Jun 18, 2013 8:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Using cp command via RunProgram
PostPosted: Thu Mar 08, 2012 11:09 pm 
Offline
User
User

Joined: Tue Dec 08, 2009 12:50 am
Posts: 15
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:
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?


Top
 Profile  
 
 Post subject: Re: Using cp command via RunProgram
PostPosted: Fri Mar 09, 2012 7:54 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Jul 02, 2009 5:42 am
Posts: 173
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:
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$


Top
 Profile  
 
 Post subject: Re: Using cp command via RunProgram
PostPosted: Sat Mar 10, 2012 2:24 am 
Offline
User
User

Joined: Tue Dec 08, 2009 12:50 am
Posts: 15
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.


Top
 Profile  
 
 Post subject: Re: Using cp command via RunProgram
PostPosted: Sun Mar 11, 2012 11:07 pm 
Offline
User
User

Joined: Tue Dec 08, 2009 12:50 am
Posts: 15
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye