How to send command to terminal ?

Questions regarding syntax

Re: How to send command to terminal ?

Postby dollyknot » Thu Nov 25, 2010 5:08 pm

Thanks for trying to help me.

I pasted the code you wrote like so.

OPTION OLDBASIC


Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String
TimeCode = Inputbox ("Time limit ")
? TimeCode
ReturnCode = shell(xboard usr/games/ -fcp crafty -tc TimeCode, TRUE)
End Sub

When I tried to execute it said xboard was an undeclared variable and to use OPTION OLDBASIC

So I set it to OLDBASIC and then tried to run it and it said

'syntax error: ) missing in line 9 near pos 29'

I've looked for shell in the documentation, but can't seem to find it :(

Sorry for being a bit of a noob but I am over 60 and find new stuff a bit hard to learn, but I used to write code years ago and have been trying to get back into it. I used to write stuff in qbasic, BBC basic and assembler. I'm hoping to make the transition to kbasic. I've tried many other languages but have not felt comfortable with them.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby Slowdown » Thu Nov 25, 2010 7:45 pm

@dollyknot,
xboard is the complete program name, correct ?
the path to xboard is usr/games, correct ?
-fcp crafty -t are commandline params, correct ?

If all three are correct then the shell command look like this,
ReturnCode = shell ("usr/games/xboard -fcp crafty -tc " & TimeCode, TRUE)

You have forgotten the " in the shell command.

If this not works you can write a file to disk (bash) and execute that one by calling the file.
I'm not working on linux so i can't help you with that one.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: How to send command to terminal ?

Postby dollyknot » Thu Nov 25, 2010 8:59 pm

I have put the changes into the code you kindly supplied and at least it don't show any errors anymore, but does not do anything else. The little code snippet you wrote seems to be a subroutine, does it need calling from a main loop to work?

The point of me writing this program is to learn kbasic, I have already made a little program that selects xboard with a game time limit that works, with this code written with yabasic.

#!/usr/bin/yabasic
input "what time limit?"t$
print t$
a$ = "-fcp crafty -tc "+t$+" -scp crafty"
system("xboard " +a$)

Once I can do this in kbasic I am on my way to writing other stuff.

I have a RedRat infrared transceiver that I want to get working.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby Henning » Thu Nov 25, 2010 11:14 pm

My suggestion, mixing code from your first and last post.

Forget option oldbasic

Code: Select all
Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String
TimeCode = Inputbox ("Time limit ")
? TimeCode
ReturnCode = shell("xboard usr/games/ -fcp crafty -tc " & TimeCode & " -scp crafty", TRUE)
End Sub


/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: How to send command to terminal ?

Postby dollyknot » Fri Nov 26, 2010 12:28 am

I have a big fat grin on my face, I am not there yet, but I am closer.

I feel as though I have made contact with geniuses.

Slowdown and Henning, I am nearly there, now it asks me for the time value, evokes xboard, but sadly does not does not tell xboard, that crafty is its engine, please translate

#!/usr/bin/yabasic
input "what time limit?"t$
print t$
a$ = "-fcp crafty -tc "+t$+" -scp crafty"
system("xboard " +a$)

to kbasic and I will open my wallet.

The code is now.

Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String
TimeCode = Inputbox ("Time limit ")
? TimeCode
ReturnCode = shell("xboard usr/games/ -fcp crafty -tc " & TimeCode & " -scp crafty", TRUE)
End Sub

And it is close to being fit for purpose.

but sadly, seems as of yet not being able to tell xboard its chess engine(s).

-fcp is an acronym for 'first chess engine' and scp sets up a second chess engine, if you want an engine match.

The reason that my code has the same engine twice, is to analyse human arrived at positions, with no programmer ability bias.

Basically if I want to analyse a position, I set it up on xboard and then let the engines resolve the position.

I want to be able to simply allocate a certain amount of time to the position analysis, both engines will spend an allocated amount of time on each move in terms of the whole game.

The gui is a different kettle of fish to the engine.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby Henning » Fri Nov 26, 2010 1:04 am

If xboard and the engines are all in usr/games/, then try:

ReturnCode = shell("usr/games/xboard -fcp crafty -tc " & TimeCode & " -scp crafty", TRUE)

You can also try with FALSE instead of TRUE.
TRUE makes shell wait for the command to finish before returning.
FALSE just starts the shell command and returns.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: How to send command to terminal ?

Postby berndnoetscher » Fri Nov 26, 2010 9:13 am

berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: How to send command to terminal ?

Postby dollyknot » Fri Nov 26, 2010 12:08 pm

I am happy to say the code below now works, the only change I had to make to Henning's suggestion, was putting a slash in front of usr like 'shell("/usr' instead of 'shell("usr' I shall now go and buy the professional KBasic, thanks to all.

Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String
TimeCode = Inputbox ("Time limit ")
? TimeCode

ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & " -scp crafty", TRUE)
End Sub
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby dollyknot » Mon Nov 29, 2010 1:24 pm

Hello,

My little program that works.

Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String
TimeCode = Inputbox ("Time limit ")
? TimeCode

ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & " -scp crafty", TRUE)
End Sub

There is a command in crafty called ponder, what it does is, either enables calculation whilst crafty waits for you to move, or disables it, basically what this does is weakens crafty.

The command line for xboard with crafty as the engine and disabling ponder would be

xboard -fcp crafty -xponder

What I would like to do is have a button on the form that toggles xboard -fcp crafty -xponder, or xboard -fcp crafty ponder.

The default is ponder on. ie shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & " -scp crafty", TRUE)

So I would imagine it to disable ponder would be something like.

shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & & PonderCode & " -scp crafty", TRUE)

With the button on the form either making PonderCode -ponder or -xponder

I've had a look around the help files and it is as clear as mud :)

What I am very unclear about is, how does one control what a button does on the form and then have it set a variable in the source code.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby berndnoetscher » Mon Nov 29, 2010 1:44 pm

Hello,

dollyknot wrote:
What I am very unclear about is, how does one control what a button does on the form and then have it set a variable in the source code.


Just create a commandbutton on the form and make a double click on it -> the code module of the form will be opened with some code for an event function.

Code: Select all
Sub CommandButton1_OnEvent()
End Sub


make it to


Code: Select all
Sub CommandButton1_OnEvent()
  MsgBox("Hello")
End Sub

and try your program.

berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

PreviousNext

Return to Coding Questions

cron