Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Oct 15, 2018 5:11 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Strange shell execute issue!
PostPosted: Fri Sep 07, 2012 2:17 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
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
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Fri Sep 07, 2012 2:47 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
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.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Fri Sep 07, 2012 2:57 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
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
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Fri Sep 07, 2012 3:29 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
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.............

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Fri Sep 07, 2012 6:56 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
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
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 12:45 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
DaveS wrote:
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



Thanks. I understand the issue now, I had no idea that it did that :)

The directory change is not actually for that reason, I can already read a directory into a list box etc. The directory change is for the CURL command that I am using in order to download a list of files from a remote server.

So basically I am doing:

cd /Applications/myapplication.app/contents/temp
curl ........

The actual directory is worked out in the program from the running program's current location and curl uses the current directory.

The above 2 commands work from terminal.


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:01 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
check out this topic..... most everything you need to know about cURL

http://forums.realsoftware.com/viewtopic.php?f=1&t=35296&p=196586&hilit=curl#p196586

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:07 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
DaveS wrote:
check out this topic..... most everything you need to know about cURL

http://forums.realsoftware.com/viewtopic.php?f=1&t=35296&p=196586&hilit=curl#p196586



Thanks, I can use CURL to upload and download the files, the problem I'm having is that curl downloads to the current directory and the current directory is root because I can't change it.... I can currently only change directory OR issue the curl command. The alternative I have at the moment is rather naff and involves writing a unix script file and running that.

Is there a simple change directory command in real basic that leaves the current process in that directory because I have not been able to find it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:11 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
Arr thanks, I did have a look and seeing your code it shows me the -T directive...... That would do it :)

I will have a mess


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:15 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
cowasaki wrote:
Arr thanks, I did have a look and seeing your code it shows me the -T directive...... That would do it :)

I will have a mess


Or maybe the download equivalent would :D........ if I could find it!


Last edited by cowasaki on Sat Sep 08, 2012 3:17 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:15 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
goto TERMINAL and type "MAN curl" and it will tell you even more... That is how I figured it all out

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:19 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
DaveS wrote:
goto TERMINAL and type "MAN curl" and it will tell you even more... That is how I figured it all out


Thanks, just reading it on-line now.......

if I find an option for the name and dir of a download file it sorts the whole problem out in one go :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange shell execute issue!
PostPosted: Sat Sep 08, 2012 3:36 pm 
Offline

Joined: Tue May 08, 2012 2:53 pm
Posts: 16
Many thanks. I've managed to sort it by using the CD command, following by a semi-colon, as mentioned earlier. I inadvertently discounted it because i'd changed my programme to use right instead of execute and it wasn't working anyway. Changed to use execute, it just works first time.


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

All times are UTC - 5 hours


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group