question

pkar avatar image
0 Votes"
pkar asked RoyLi-MSFT commented

UWP console app

I want my UWP app to be really Universal. I mean, it should work as normal Windows app, but also with command line interface.

I know I can
(1) make execution alias, and access command line parameters:
https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.activation.commandlineactivatedeventargs

(2) make command line app: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/console-uwp

To add some command line support, I used method (1).
But I cannot (or, I don't know how) write to console from such app. I can only read command line arguments (and, e.g., send Bluetooth packet to my bulb to change color).

There is also (2), so I added RemoteSystem support for my main app, and make small console app to send commands from command line via RemoteSystem to my main app, and use Console.WriteLine to print output received from my main app via RemoteSystem.
But it seems that console app cannot use RemoteSystem (oAppSrvConn.OpenAsync() exception - but same code used in another UWP app works ok).

So, is there any possibility to have universal app written in UWP? I mean, same app for command line in/out, and for Windows UI?
Or, maybe, last implementation of idea of universal app was IBM OS/360? :)

windows-uwp
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

One auto-comment :)
I got idea to test one thing, and it seems like (1) can be installed on phone. I used examples as basis (as there is no real documentation), but now I added uap5 as ignorable namespace - in this way, app can be installed on phone.

But still, I'm not able to write to stdout from such app :(

0 Votes 0 ·

Await oAppSrvConn.OpenAsync() doesn't throw exception.
When I debugging app, app ends on this call, without throwing exception.

0 Votes 0 ·

IBM OS/360 is extremely old. Its main interface was punched cards in and the printer out. Later the Time Sharing Option (TSO) was added for I/O using dumb terminals. Unix was among the first operating systems that supported console type interfaces for applications and standard I/O is a concept that originated with it and the C language.

0 Votes 0 ·

I referred to possibility to run same code on all systems - big machines, with all instructions hard coded, and very small machines, with instructions "software emulated" :)

I want to add command line interface to UWP app, directly or via "medium/interface app", e.g. app translating command line to RemoteSystem (AppService).
Many my apps checks some things periodically, show alerts, etc., and I want command line to enable getting some data from data downloaded/cached by app.

0 Votes 0 ·

Note that Universal Windows Platform (UWP) applications are called universal but they are also called Windows. A UWP application requires Windows. And the smallest Windows device is more powerful than any OS/360 system. And platform independence did not exist in the OS/360 era.


0 Votes 0 ·
Show more comments

E.g. my RGB LED app - windows version shows MainPage, allows to scan for Bluetooth LED devices, to set required light (three sliders, for R, G and B), and send command to LED bulb.
I added ability (via commandlineactivatedeventargs) to send commands to bulbs ("rgbled BluetoothMAC Rvalue Gvalue Bvalue"), but I also want to console.writeline ("Everything OK"), or "ERROR: bulb not found", or something like that.
Also, command like "rgbled show devices", to display (dump) devices known by app. Etc.

0 Votes 0 ·

1 Answer

SimpleSamples avatar image
0 Votes"
SimpleSamples answered pkar commented

I think you need to develop a Class Library application and then two separate applications that use it, one for a console interface and another for a GUI interface. You do not state what language you are using; for C++ you might need to use a Windows Runtime Component instead of Class Library. This configuration is consistent with other types of applications.

If you must develop one application that supports both types of UIs then you could develop a text-only interface in a GUI application but Standard I/O could not be supported.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

All my apps (about 30 in Microsoft Store) started as UWP/VB apps.
Some of them are converted to C#/Uno platform, as some time ago I thought about switching from Lumia Phone to Android phone. But now, I think I stick to Windows Phone as long as it will be possible. Android is just much worse OS than Windows, has slovenly user interface, many security problems, etc., and iOS is too expensive.
I want to add commandline to existing apps, so users of my apps would have new functionality and no data loss.
One of app, MijiaThermo, downloads (via Bluetooth) data from temperature sensors, and creates log file (every hour). Another, SMS backup, runs about midnight, and backups (dumps) SMSs received/sent in this day. Another, SmogMeter, downloads data about environment (from many web services), and alerts when e.g. PM10 is outside health range.
As far as I know, converting app as you recommend, would lead to have new app, and losing history of accumulated data.

0 Votes 0 ·