Solved

Command prompt output in Win CE

Posted on 2014-03-21
4
455 Views
Last Modified: 2014-03-24
I'm working on a VB.NET program for a Windows CE device. In part of the program I want to open a console program, pass it an argument and read the output. The below code works perfectly in a standard Windows Form program, but will not work in the Windows CE environment.

    Public Function GET_PW_CS(ByVal stIN As String) As String

        'INPUTS: stIN = the argument (passkey) for the  string desired
        'OUTPUTS: The string from the console program

        'Set up the Process
        Dim pInfo As New ProcessStartInfo()
        pInfo.FileName = "C:\MyConsoleProgram.exe"
        pInfo.Arguments = stIN
        pInfo.RedirectStandardOutput = True
        pInfo.UseShellExecute = False
        pInfo.CreateNoWindow = True


        'Calls the program and gets the output
        Dim p As Process = Process.Start(pInfo)
        GET_PW_CS = p.StandardOutput.ReadLine()
        p.WaitForExit()

        pInfo = Nothing
        p.Dispose()

    End Function

Open in new window


These lines aren't recognized as being valid in CE:

pInfo.RedirectStandardOutput = True
pInfo.CreateNoWindow = True
 GET_PW_CS = p.StandardOutput.ReadLine()

Any suggestions? Perhaps there is a completely different way to accomplish this?

Thanks in advance
0
Comment
Question by:pdi656
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 39946987
As Windows CE has only very limitted resources the tools, runtimes and applications have been stripped down. So Compact Framework only and native C API supports only a subset of what is available in full framework and desktop windows.

Although Windows CE offers a command prompt, there is no API to redirect stdin, stderror and stdout back to compact framework.

You need to workaround this if you need to cpature the output of an console app. >ou can redirect output to a file and then in your code wait until the console process has terminated and then read the file.

See also: http://msdn.microsoft.com/en-us/library/aa453925.aspx
0
 
LVL 1

Author Comment

by:pdi656
ID: 39950707
I set up my console app to write the output to a file. I then tried calling the console app from my program, but it errors out when trying to run the console app. The console app is on our internal network, as is the text file. For some reason it doesn't like executing my command prompt from the network. When I copy the command prompt to the mobile device itself and call it from there I get a MissingMethodException error.

All I'm trying to accomplish is that I'm trying to dynamically get a database connection string for the software on the mobile device to use. We will be moving several database servers over the next few months. Because the connection strings are coded into the software, the only way for the devices to work properly is if I re-install the software on each device on the day of the server switch. My thinking is that if the program dynamically looks up the connection when the software starts, the servers can be moved anytime and all I have to do is change the connection string in one spot (the console program).

If there is another way to accomplish this, I'm open for it.
0
 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
ID: 39951168
There are varous ways to 'update' software on Windows CE devices, but all of them require coding.

Idea 1) You have your connection string extern to the main app. For example in a file or in registry. Then have either an update application or update code in mail app that reads the setting from a server and updates the registry/the file.

Idea 2) Your main app implements a server (ie http or simple socket) that can be reached from outside the device. Then have a desktop app that accesses the server and changes setting.

Idea 3) you implement a separate server and make changes from desktop PC custom app. For example see my extended webserver at http://www.hjgode.de/wp/2012/10/19/windows-mobile-a-simple-web-server-with-extended-features/

Idea 4) Possibly your device already supports any config tool. For example config by barcodes or files sent to specific locations or has a ready to use ftp server.

Idea 5) You have many devices and already thought about remote management of these. Take a look at SOTI MobilControl or Wavelink.

Idea 6) You get every device at your hands and dock it to your PC. Then create automated task that updates every device via ActiveSync/WMDC. ActiveSync automation example at http://www.hjgode.de/wp/2010/02/26/pc-activesync-can-be-used-to-automate-tasks-on-device-connection/

Idea 7) Create a process that watches a dir and then takes config files like WAP provisioning ones and use DMProcessConfig to change device settings/registry.  Needs your app uses an external storage for custom connection string etc.

...

Can you tell which devices you are talking about? Some manufacturers provide free management tools.
0
 
LVL 1

Author Closing Comment

by:pdi656
ID: 39951230
Great suggestions. Sounds like I should have hired you to set all of this up in the first place! I thought about storing it in the registry, but I wasn't sure how I'd be able to change it remotely. I didn't want it in a file as I was worried that someone would see it. Not that they couldn't get into the registry, but they are less likely to there.

These devices have barcode readers on them. I may simply send the updated data in the form of a barcode and have the user scan it into a utility in my program that will update the connection string in the registry - a combination of two of your suggestions. I'm still going to explore some of your other suggestions too. Thanks for the ideas!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now