Hi Everyone!
Does anyone have any example of using the console.device under Os4. With the library interface style. I have found some examples on the internet but they are ancient and in old style. I only need a quick and easy example, that opens the console, writes some text to it, receives some text from it, and closes it would be great.
Thanks,
Yogi
@Yogi37
Generally you do not want to use console.device directly in a program. Pretty much the only reason for doing so is if you are writing a replacement/custom con-handler. If you just want to interact with the shell from your shell-launched program then you should stick to access uing Input() and Output() filehandles. For more advanced input you can always use the SetMode() function to switch the Shell to RAW mode:
If you still want to try using console.device there is some old code (from 2006) that I've written for command-line style calculator that I never finished. The commandline part using console.device is there, just not the calculating part. It even has some menus that are generated from a xml-like file format.
The source code for it is available here if you're interested:
https://dl.dropbox.com/u/26599983/clcalc-wip-src.7z
Thanks alot for the help, and what I wanted to do with the console.device doesn't make sense after reading your post. But I appreciate the example code and it was very helpful. Thanks.
Yogi
Hi Yogi,
While I'm still learning all this too, I can pass on some things I've
encountered...
To start with, I believe OS4 will automatically open a console window for an app
started from the Workbench (in Workbench mode) as soon as it starts calling
printf's.
By "Workbench mode", I mean that in the app's WBInfo second page, it is set to
"Start from" the Workbench. Of course, you can also set that to start from Shell
and turn off the prompting.
When your application does rely on the OS to automatically open the console for
it, you can define what kind of console window is opened for your app by
making a variable declaration like this at the start of your app:
const char* __stdiowin UNUSED = "CON:100/100/600/350/MyAppConsole/CLOSE";
The OS will find that defintion and open the console accordingly. When your
app closes, the window is closed.
Finally, you should also be able to "manually" open a console window for your
app by using the standard file open/read/write/close commands and a filename
string like the one above. This is a "high level" CON: access, as opposed to
the "low-level" console.device access Salass00 mentioned.
While I haven't gone down the route of opening the CON: too much, it's been
around forever and should be well documented elsewhere.
Good luck,
PJS