473,714 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing "unknown" command line in C#

[Reposting this in this group since a helpful soul pointed out that
microsoft.publi c.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.ex e /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.Diagnost ics.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 2453
Rune,

Try passing the full command line to the ProcessStartInf o 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.co m

"Rune Jacobsen" <rune.jacobsen@ no_spam.broadpa rk.no> wrote in message
news:43******** @news.broadpark .no...
[Reposting this in this group since a helpful soul pointed out that
microsoft.publi c.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.ex e /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.Diagnost ics.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
2932
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; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en
0
1518
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> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> <ds:SignatureMethod
0
1504
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 available conversion for the source code page "1114" to
3
6648
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" has type "unknown" DETAIL: Proceeding with relation creation anyway. CREATE VIEW Or is this warning just noise in this case?
0
2163
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 the following in my php-error.log: PHP Warning: Unknown: A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0
7
5560
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, with different file names each time. So i'm writing into the code to ask the user how many files, and what their names are. From each we'll read in 2 lines, then do some math using all of those lines. Then do it again on another set of lines. ...
9
10737
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 as a valid return value for the typeof operator in a later version of ECMAScript or is this a JScript "feature"? -- Klaus Johannes Rusch
6
2765
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 complier reduced my errors but I'm still having trouble. I think I have all the correct paths set but I'm not sure. F2PY gets further when I specifically tell it what my compilers are as follows................. C:\Program...
0
2627
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 "python/velLaunchCode.py", line 61, in __init__ File "python/velLaunchCode.py", line 143, in Unix File "python/subprocess.py", line 599, in __init__ File "python/subprocess.py", line 1031, in _execute_child File "/usr/lib/python2.3/pickle.py", line 1394, in...
0
8817
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9322
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9037
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7963
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6641
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4734
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3170
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.