473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Executing "unknown" command line in C#

[Reposting this in this group since a helpful soul pointed out that
microsoft.public.dotnet.csharp.general has very low traffic, despite one
probably accurate answer, I'll try my luck here as well]

Hi,

I've been trying to figure this one out, but my experience just doesn't
have what it takes... :|

I am writing an application that reads an XML file and displays the
contents in various ways to the end user. This works fine. My challenge
lies in the fact that these XML files are generated by various (third
party) applications. Which application generates them depends on the
user, the country they are in, their personal preferences, the features
of the applications etc. Basically, there can be any number of them, and
I probably don't even know 10% of the alternatives.

However, since I am a thoughtful developer that wants to listen to my
users, I don't want them to have to do this XML-grabbing by themselves.
Sure, some do it the old way in a DOS box, others just download the file
from the web somewhere, others make scheduled tasks in Windows etc. The
thing they have in common is that there is always a command line to grab
a fresh copy of the XML file. So I implemented a simple scheduler in my
app that should run the XML file generator/grabber of choice once a day,
once a week or whatever.

Here comes the problem; I want the user to be able to easily tell my
application what it needs to do in order to grab the file. So let's say
we have three users X, Y and Z who need to run these commands in order
to grab their stuff:

X: superblala.exe -grab
Y: justgrabit.exe
Z: complexthing.exe /x /fwahey.xml /b /u /g

What I've done is to add a "..." button to allow the user to browse for
the executable. Then they have to manually type in the arguments
afterwards (well, not Y, since he has a dedicated .exe for grabbing).

So you may begin to see my problem. I have a string that needs to be
executed. And it works fine if you execute it from a DOS box, a
scheduled task in the OS, or Start -> Run. However, if I want to do it
the proper .net way (as far as I can tell), I have to use one of the
System.Diagnostics.Process ways of doing it. And this creates the core
of my problem - to do this, I have to divide my command line into two
strings - one for the .exe (or whatever) file, another for the
arguments. The way I see it, these are my options:

1) Create two text boxes. One for the exe file (connected to the Browse
button), another for the arguments.

2) Do some magic on the string and figure out what part of it is the
actual command, and what part is the arguments.

3) Create a temporary .bat file on the fly and execute it.

4) Use the super magic happy solution that one of the people reading
this post who knows a lot more than me about C# and .net comes up with
that allows me to just tell the OS to run the damn thing and never mind
where the command stops and the parameters start.

So I have thought quite a bit about this. 1 might be the way to go, but
for me, an old command line warrior, it feels a bit counter-intuitive
and wrong. Solution 2 is the Rambo way of doing it, and is far from
impossible, but sounds like quite a bit of work and time that I would
rather spend on other aspects of my application. Number 3 is the easy
way out for sure, but also feels kinda like a cheat. So what I'm hoping
for is that this post will make someone come up with a beautiful and
elegant version of solution 4, where I just push my string into the
operating system somewhere, and then it does its job of figuring such
things out, instead of burdening poor me with it.

So, what do you say? Am I doomed? Or is there hope?

Thanks for any insight!

Rune
Jan 2 '06 #1
1 2425
Rune,

Try passing the full command line to the ProcessStartInfo instance as
the filename. Also, make sure that UseShellExecute is set to false (since
you know the name of the exe, you shouldn't need to use shell execution).

It should then call CreateProcess, which will pass the full command line
to CreateProcess as the command line attribute (with the executable name).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rune Jacobsen" <rune.jacobsen@no_spam.broadpark.no> wrote in message
news:43********@news.broadpark.no...
[Reposting this in this group since a helpful soul pointed out that
microsoft.public.dotnet.csharp.general has very low traffic, despite one
probably accurate answer, I'll try my luck here as well]

Hi,

I've been trying to figure this one out, but my experience just doesn't
have what it takes... :|

I am writing an application that reads an XML file and displays the
contents in various ways to the end user. This works fine. My challenge
lies in the fact that these XML files are generated by various (third
party) applications. Which application generates them depends on the user,
the country they are in, their personal preferences, the features of the
applications etc. Basically, there can be any number of them, and I
probably don't even know 10% of the alternatives.

However, since I am a thoughtful developer that wants to listen to my
users, I don't want them to have to do this XML-grabbing by themselves.
Sure, some do it the old way in a DOS box, others just download the file
from the web somewhere, others make scheduled tasks in Windows etc. The
thing they have in common is that there is always a command line to grab a
fresh copy of the XML file. So I implemented a simple scheduler in my app
that should run the XML file generator/grabber of choice once a day, once
a week or whatever.

Here comes the problem; I want the user to be able to easily tell my
application what it needs to do in order to grab the file. So let's say we
have three users X, Y and Z who need to run these commands in order to
grab their stuff:

X: superblala.exe -grab
Y: justgrabit.exe
Z: complexthing.exe /x /fwahey.xml /b /u /g

What I've done is to add a "..." button to allow the user to browse for
the executable. Then they have to manually type in the arguments
afterwards (well, not Y, since he has a dedicated .exe for grabbing).

So you may begin to see my problem. I have a string that needs to be
executed. And it works fine if you execute it from a DOS box, a scheduled
task in the OS, or Start -> Run. However, if I want to do it the proper
.net way (as far as I can tell), I have to use one of the
System.Diagnostics.Process ways of doing it. And this creates the core of
my problem - to do this, I have to divide my command line into two
strings - one for the .exe (or whatever) file, another for the arguments.
The way I see it, these are my options:

1) Create two text boxes. One for the exe file (connected to the Browse
button), another for the arguments.

2) Do some magic on the string and figure out what part of it is the
actual command, and what part is the arguments.

3) Create a temporary .bat file on the fly and execute it.

4) Use the super magic happy solution that one of the people reading this
post who knows a lot more than me about C# and .net comes up with that
allows me to just tell the OS to run the damn thing and never mind where
the command stops and the parameters start.

So I have thought quite a bit about this. 1 might be the way to go, but
for me, an old command line warrior, it feels a bit counter-intuitive and
wrong. Solution 2 is the Rambo way of doing it, and is far from
impossible, but sounds like quite a bit of work and time that I would
rather spend on other aspects of my application. Number 3 is the easy way
out for sure, but also feels kinda like a cheat. So what I'm hoping for is
that this post will make someone come up with a beautiful and elegant
version of solution 4, where I just push my string into the operating
system somewhere, and then it does its job of figuring such things out,
instead of burdening poor me with it.

So, what do you say? Am I doomed? Or is there hope?

Thanks for any insight!

Rune

Jan 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert | last post by:
did you solve this problem? It seems to be still present here with py2.3.5. Robert -- From: Manish Jethani <manish.j@gmx.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;...
0
by: David Mediavilla | last post by:
I am trying to check a SOAP signature with WSE 1.0 SP1, but with a certain transform I only get an "Unknown tranform" exception. The SOAP signature is like this: <ds:Signature>...
0
by: wilsonchan1000 | last post by:
There is a note regarding this error in UDB. I eventually found a solution and want to share with all or you. Problem occur with connect to db2 server: SQLCODE : -332 SQL0332N There is no...
3
by: Ed L. | last post by:
On 7.4.6, is there any problem with defining one column of a view to be a string literal? For example ... $ psql -c "create view fooview as select 'bar' as footype" WARNING: column "footype"...
0
by: Shaun | last post by:
Hi all, I'm trying to implement a custom session handler that writes session data to a MySQL database. It works fine about 99% of the time. Trouble is, at random intervals, I get entries like...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
9
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined...
6
by: Sile | last post by:
Hello, I'm trying to get f2py working from the command line on windows XP. I have mingw32 as my C complier (after some advice on a previous thread) and Compaq Visual Fortran 6.5. Changing my C...
0
by: Jeff Groves | last post by:
I'm using FreezePython on a Python program that uses wxPython and subprocess. The result almost works, but it always hits this bug: File "velauncher.py", line 847, in Launch File...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.