New topic: 

Strange shell execute issue!

<http://forums.realsoftware.com/viewtopic.php?t=45286>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        cowasaki          Post subject: Strange shell execute 
issue!Posted: Fri Sep 07, 2012 2:17 pm                         
Joined: Tue May 08, 2012 2:53 pm
Posts: 6                I've spent two hours now banging my head against a 
wall!  I can use the shell.execute command and have done regularly but it does 
not seem to work with the cd command !

This is my test function:

Note:

DownloadFileList.text = string containing the filename of a file on a server 
which needs to be downloaded.

window1.HiddenTextArea = a simple text box where the output goes......  It 
starts with a line showing the 'cd' command that I am TRYING to use

dim f as FolderItem
dim path as string
dim sh as new shell

f=GetFolderItem("")

path=f.Shellpath

MsgBox path

' If this is in run mode leave out the .app part
'
if app.RunMode=false then
  path=path+"/Controller.app"
end if
path=path+"/Contents/Temp"


MsgBox "Download: "+DownloadFileList.text+" to:  "+path


sh.Backend = "bash"
sh.Arguments = "-c"

window1.HiddenTextArea.Text= "cd "+path+chr(10)+chr(10)

sh.Execute "ls"
while sh.IsRunning
wend
window1.HiddenTextArea.Text = window1.HiddenTextArea.Text+chr(10)+sh.Result

sh.Execute "cd"
while sh.IsRunning
wend
window1.HiddenTextArea.Text = window1.HiddenTextArea.Text+chr(10)+sh.Result

sh.Execute "ls"
while sh.IsRunning
wend
window1.HiddenTextArea.Text = window1.HiddenTextArea.Text+chr(10)+sh.Result

sh.Execute "cd /Users/darren/Programming"
while sh.IsRunning
wend
window1.HiddenTextArea.Text = window1.HiddenTextArea.Text+chr(10)+sh.Result

sh.Execute "ls"
while sh.IsRunning
wend
window1.HiddenTextArea.Text = window1.HiddenTextArea.Text+chr(10)+sh.Result



And the output is:

the cd command that works from terminal (and what I am actually trying to use)
ls of the root directory
ls of the root directory
ls of the root directory

What is SHOULD (or more precisely what I would LIKE to) be outputting is:

the cd command that works from terminal (and what I am actually trying to use)
ls of whatever directory the program is currently running in
ls of the home directory
ls of the directory home/Programming

Nothing I do with the cd command affects the current directory.......   
                             Top                pony          Post subject: Re: 
Strange shell execute issue!Posted: Fri Sep 07, 2012 2:47 pm                    
             
Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1148
Location: DFW area, Texas, USA                Nothing strange at all. Imagine 
using Terminal, and for every command you send you open a new window before 
sending it. Look familiar?
The Shell class has 3 modes.

Look at the "Interactive Shell.rbp" sample project to see how to use a Shell 
interactively.      
_________________
Fly like a mouse, run like a cushion, be the small bookcase.
http://www.wish-sandwich.com  
                             Top                cowasaki          Post subject: 
Re: Strange shell execute issue!Posted: Fri Sep 07, 2012 2:57 pm                
         
Joined: Tue May 08, 2012 2:53 pm
Posts: 6                pony wrote:Nothing strange at all. Imagine using 
Terminal, and for every command you send you open a new window before sending 
it. Look familiar?
The Shell class has 3 modes.

Look at the "Interactive Shell.rbp" sample project to see how to use a Shell 
interactively.


I've just tried 

sh.mode = 0, 1 & 2

and none of them has the desired effect 

Will have a look at the program you mention now.............   
                             Top                pony          Post subject: Re: 
Strange shell execute issue!Posted: Fri Sep 07, 2012 3:29 pm                    
             
Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1148
Location: DFW area, Texas, USA                You are going to need to more 
than guess as to what is required. The sample code illustrates it. I also 
recommend you read the Language Reference.
Instead of execute you will use write, anyway, examine the code before simply 
saying it doesn't have the desired effect.


cowasaki wrote:I've just tried 

sh.mode = 0, 1 & 2

and none of them has the desired effect 

Will have a look at the program you mention now.............      
_________________
Fly like a mouse, run like a cushion, be the small bookcase.
http://www.wish-sandwich.com  
                             Top                DaveS          Post subject: 
Re: Strange shell execute issue!Posted: Fri Sep 07, 2012 6:56 pm                
                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4102
Location: San Diego, CA                each time you call SH.EXECUTE you are 
creating a new session.... the command you supply is executed in that session, 
and the result is returned

So when you say "CD xxx".... the session you open, does the CD command, and 
returns
the next SH.EXECUTE says "LS".... a new session opens and does the "LS"..... 
BUT IT HAS NO CLUE about the CD command you just did, becuase THAT session is 
gone already.

You can stack commands up "CD xxx;LS" to have them in the same session.


But I submit.... WHY use SHELL to get directory information?
That is what a FOLDERITEM is good at

f=specialfolder.users.child("darren").child("Programming")
for i=0 to f.count
  msgbox f.trueitem(i)
next i
      
_________________
Dave Sisemore
MacPro, OSX 10.7.3 RB2011r3
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to