Board index » delphi » Is this possible?

Is this possible?

Its a GUI app but I want it to run from the command line if the user is
running it from the command line and instead of outputting message boxes
print to the DOS windows instead.

      if FindCmdLineSwitch(s,sc,True) then
      begin
         writeln('Usage:  usage goes here);
         PrintMessage('Usage:  usage goes here);
      end;

I get an IO error with this above.  Any ideas?

--
Thanks lots

 

Re:Is this possible?


Create a new console project and you'll see some compiler directives
in the .dpr file. Those must probably be set for writeln (and other
console-oriented procedures) to work.
I'm not really sure, but I think you cannot mix GUI and console code in one
application.

Quote
"Max Adams" <{*word*221}Ducky...@hotmail.com> wrote in message

news:w2aT7.933$4w1.20941@news-binary.blueyonder.co.uk...
Quote
> Its a GUI app but I want it to run from the command line if the user is
> running it from the command line and instead of outputting message boxes
> print to the DOS windows instead.

>       if FindCmdLineSwitch(s,sc,True) then
>       begin
>          writeln('Usage:  usage goes here);
>          PrintMessage('Usage:  usage goes here);
>       end;

> I get an IO error with this above.  Any ideas?

> --
> Thanks lots

Re:Is this possible?


you can redirect output to the console through use of Windows API calls.

--

Regards,

Dan Donoghue
Always be yourself.  You need to be someone and everyone else is taken.

Quote
fat G wrote in message ...
>Create a new console project and you'll see some compiler directives
>in the .dpr file. Those must probably be set for writeln (and other
>console-oriented procedures) to work.
>I'm not really sure, but I think you cannot mix GUI and console code in one
>application.

>"Max Adams" <{*word*221}Ducky...@hotmail.com> wrote in message
>news:w2aT7.933$4w1.20941@news-binary.blueyonder.co.uk...
>> Its a GUI app but I want it to run from the command line if the user is
>> running it from the command line and instead of outputting message boxes
>> print to the DOS windows instead.

>>       if FindCmdLineSwitch(s,sc,True) then
>>       begin
>>          writeln('Usage:  usage goes here);
>>          PrintMessage('Usage:  usage goes here);
>>       end;

>> I get an IO error with this above.  Any ideas?

>> --
>> Thanks lots

Re:Is this possible?


any idea which API's?

Quote
"Dan Donoghue" <d...@d-soft.co.uk> wrote in message

news:hlaT7.3270$Jm.180458@stones...
Quote
> you can redirect output to the console through use of Windows API calls.

> --

> Regards,

> Dan Donoghue
> Always be yourself.  You need to be someone and everyone else is taken.

> fat G wrote in message ...
> >Create a new console project and you'll see some compiler directives
> >in the .dpr file. Those must probably be set for writeln (and other
> >console-oriented procedures) to work.
> >I'm not really sure, but I think you cannot mix GUI and console code in
one
> >application.

> >"Max Adams" <{*word*221}Ducky...@hotmail.com> wrote in message
> >news:w2aT7.933$4w1.20941@news-binary.blueyonder.co.uk...
> >> Its a GUI app but I want it to run from the command line if the user is
> >> running it from the command line and instead of outputting message
boxes
> >> print to the DOS windows instead.

> >>       if FindCmdLineSwitch(s,sc,True) then
> >>       begin
> >>          writeln('Usage:  usage goes here);
> >>          PrintMessage('Usage:  usage goes here);
> >>       end;

> >> I get an IO error with this above.  Any ideas?

> >> --
> >> Thanks lots

Re:Is this possible?


Quote
fat G wrote in message ...
>Create a new console project and you'll see some compiler directives
>in the .dpr file. Those must probably be set for writeln (and other
>console-oriented procedures) to work.
>I'm not really sure, but I think you cannot mix GUI and console code in
one
>application.

Windows has separate subsystems for things like win32, win16,
console, posix, os/2, and possibly more. The executable header
contains information about the subsystem that a program runs
in, so you may be right and it's impossible.

Max, did you try opening a file to the "con:" device? Untested,
but it used to work before all this GUI stuff came about, and
may still.

Groetjes,
Maarten Wiltink

Quote
>"Max Adams" <{*word*221}Ducky...@hotmail.com> wrote in message
>news:w2aT7.933$4w1.20941@news-binary.blueyonder.co.uk...
>> Its a GUI app but I want it to run from the command line if the user is
>> running it from the command line and instead of outputting message boxes
>> print to the DOS windows instead.

>>       if FindCmdLineSwitch(s,sc,True) then
>>       begin
>>          writeln('Usage:  usage goes here);
>>          PrintMessage('Usage:  usage goes here);
>>       end;

>> I get an IO error with this above.  Any ideas?

Re:Is this possible?


GetStdHandle to get a valid handle for the console

WriteConsole or WriteFile to write to the console.

Given that you are running a standard 32bit GUI application you may need to
use AllocConsole/FreeConsole, CreateProcess or CreateFile to create a valid
console before you can read/write from/to it.

--

Regards,

Dan Donoghue
Always be yourself.  You need to be someone and everyone else is taken.

Quote
{*word*221} Ducky wrote in message <9vjd4h$fo0o...@ID-116287.news.dfncis.de>...
>any idea which API's?

>"Dan Donoghue" <d...@d-soft.co.uk> wrote in message
>news:hlaT7.3270$Jm.180458@stones...
>> you can redirect output to the console through use of Windows API calls.

>> --

>> Regards,

>> Dan Donoghue
>> Always be yourself.  You need to be someone and everyone else is taken.

>> fat G wrote in message ...
>> >Create a new console project and you'll see some compiler directives
>> >in the .dpr file. Those must probably be set for writeln (and other
>> >console-oriented procedures) to work.
>> >I'm not really sure, but I think you cannot mix GUI and console code in
>one
>> >application.

>> >"Max Adams" <{*word*221}Ducky...@hotmail.com> wrote in message
>> >news:w2aT7.933$4w1.20941@news-binary.blueyonder.co.uk...
>> >> Its a GUI app but I want it to run from the command line if the user
is
>> >> running it from the command line and instead of outputting message
>boxes
>> >> print to the DOS windows instead.

>> >>       if FindCmdLineSwitch(s,sc,True) then
>> >>       begin
>> >>          writeln('Usage:  usage goes here);
>> >>          PrintMessage('Usage:  usage goes here);
>> >>       end;

>> >> I get an IO error with this above.  Any ideas?

>> >> --
>> >> Thanks lots

Re:Is this possible?


perhaps a neater way to do what u want is to have a console application
which in turn launches a GUI application?  The GUI app can send messages
back to the console app, if it was used to start the app, which can then
display the results at the prompt.

--

Regards,

Dan Donoghue
Always be yourself.  You need to be someone and everyone else is taken.

Quote
Max Adams wrote in message ...
>Its a GUI app but I want it to run from the command line if the user is
>running it from the command line and instead of outputting message boxes
>print to the DOS windows instead.

>      if FindCmdLineSwitch(s,sc,True) then
>      begin
>         writeln('Usage:  usage goes here);
>         PrintMessage('Usage:  usage goes here);
>      end;

>I get an IO error with this above.  Any ideas?

>--
>Thanks lots

Other Threads