473,387 Members | 1,721 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,387 software developers and data experts.

External process fails with switch arguments

I am attempting to fetch data from an external process. It seems to work OK
with regular arguments, but not with switch arguments. Here is an example of
a failure:
===================================
ProcessStartInfo psi = new ProcessStartInfo("date","/t");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
process = new Process();
process.StartInfo = psi;
process.Start();
===================================

My Nunit test case returns this:
===================================
TestCase 'CleanCodeTest.IO.ExecProcessTest.TestOneSwitchArg '
failed: Expected string length 13 but was 27. Strings differ at index 0.
Expected: "Wed 6/20/2007"
But was: "*** date: invalid date `/t'"
===================================

The MSDN documentation for ProcessStartInfo.Arguments sheds no light on
this; it is extremely sparse, essentially providing just an example and no
descriptive text.
Jun 20 '07 #1
7 2943
Hi Michael,

From your description, you're using the System.Diagnostics.Process class to
launch some external program, but got some error behavior, correct?

Based on the code snippet you provided, the external program you launch is
a "date" application and will take some commandline arguments. Would you
provide some further information on the date application's code logic or
what's the expected behavior if you launch it interactively (without using
Process class) in commandline or through shell?

Also, I'm wondering whether the "date" program is also developed by you or
your team and if you have source code or symbol to perform live debugging
against it. If so, that'll be quite helpful for us to do further problem
tracking.

Please feel free to let me know if there is anything I missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 21 '07 #2
Sometimes you think too hard :-)

I am simply using the DOS "date /t" command here which should return a value
like that shown in my test case. And it seems pretty clear that the problem
is in the .Net interface, not the "date" program itself.
Jun 21 '07 #3

"michael sorens" <m_********@newsgroup.nospamwrote in message
news:9B**********************************@microsof t.com...
Sometimes you think too hard :-)

I am simply using the DOS "date /t" command here which should return a
value
like that shown in my test case. And it seems pretty clear that the
problem
is in the .Net interface, not the "date" program itself.
And I already independently produced his expected output, and verified that
it is "date.exe" being run, not a cmd.exe builtin.
Jun 21 '07 #4
On Thu, 21 Jun 2007 09:56:01 -0700, michael sorens
<m_********@newsgroup.nospamwrote:
Sometimes you think too hard :-)
I think you're being too hard on him. He's just looking at your question
at face value, assuming that everything you've done there is intentional..
I am simply using the DOS "date /t" command here which should return a
value
like that shown in my test case. And it seems pretty clear that the
problem
is in the .Net interface, not the "date" program itself.
Well, except for the fact that the "date" that takes "/t" as an argument
isn't an executable program you can start using the fileName parameter of
the ProcessStartInfo class. If you go to a command prompt in Windows and
type "date", you get the built-in "date" command by default, but you can't
use that "date" command as input to the creation of a process.

On my PC, I don't even have a "date" executable anywhere, and I can't
start a process using that as the fileName parameter. If you do have a
"date" executable that you are running (as it appears that you do), then
you need to determine the correct arguments to use to get the output you
desire. From your original post, it appears that "/t" is not the correct
argument (though it is with the built-in "date" command).

For what it's worth, if you use this to create your ProcessStartInfo, you
get what you're asking for:

ProcessStartInfo psi = new ProcessStartInfo("cmd", "/c date
/t");

Though, it doesn't use your installed "date.exe" program, so if that was
intentional, you'll have to figure out what arguments to pass to your
installed "date.exe" program (as I suggest above).

Pete
Jun 21 '07 #5
Looks like false assumptions got in the way on both sides of the aisle here.
Once I became clued in from Peter's post, I saw why. To me, when I specified
"date" I expected to execute "date", just as if I typed it on the command
line. I did not imagine there were two different types of date, one builtin
and one standalone. Now all the prior discussion makes sense, and I see why
"cmd /c date /t" will, in fact, do what I expect.

Much obliged to all.
Jun 21 '07 #6
Interestingly, for me "date.exe /t" gives the expected output. Is that
still running a cmd.exe builtin? If so, I'd classify that as a bug.

(Tries with cygwin)
$ date.exe /t
date: invalid date `/t'
$ which date.exe
/usr/bin/date.exe

Seems like you might be running the cygwin (gnu-utils) version of date by
mistake. Check your path.

(Uses filemon to see what date.exe cmd calls)
No hits....

(Uses taskmgr to see what date.exe cmd calls)
None.

Looks like not only is "date" a cmd.exe builtin, so is "date.exe"??? Looks
like a bug...
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Thu, 21 Jun 2007 09:56:01 -0700, michael sorens
<m_********@newsgroup.nospamwrote:
Sometimes you think too hard :-)
I think you're being too hard on him. He's just looking at your question
at face value, assuming that everything you've done there is intentional.
I am simply using the DOS "date /t" command here which should return a
value
like that shown in my test case. And it seems pretty clear that the
problem
is in the .Net interface, not the "date" program itself.
Well, except for the fact that the "date" that takes "/t" as an argument
isn't an executable program you can start using the fileName parameter of
the ProcessStartInfo class. If you go to a command prompt in Windows and
type "date", you get the built-in "date" command by default, but you can't
use that "date" command as input to the creation of a process.

On my PC, I don't even have a "date" executable anywhere, and I can't
start a process using that as the fileName parameter. If you do have a
"date" executable that you are running (as it appears that you do), then
you need to determine the correct arguments to use to get the output you
desire. From your original post, it appears that "/t" is not the correct
argument (though it is with the built-in "date" command).

For what it's worth, if you use this to create your ProcessStartInfo, you
get what you're asking for:

ProcessStartInfo psi = new ProcessStartInfo("cmd", "/c date
/t");

Though, it doesn't use your installed "date.exe" program, so if that was
intentional, you'll have to figure out what arguments to pass to your
installed "date.exe" program (as I suggest above).

Pete
Jun 25 '07 #7
On Mon, 25 Jun 2007 10:41:31 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nospamwrote:
Interestingly, for me "date.exe /t" gives the expected output. Is that
still running a cmd.exe builtin? If so, I'd classify that as a bug.
Well, then it's a bug that's been in the command line interpreter for
ages. My recollection is that the DOS CLI has always treated any name
followed by .exe or .com as the built-in command if no matching program is
found. Maybe I'm wrong and this was new to DOS 2.0 (which introduced a
lot of new features, relatively speaking). Hard to remember for sure,
going that far back.

But that shouldn't imply that a different mechanism that doesn't go
through the CLI should produce the same behavior. There's a big
difference between using an interactive interpreter and simply telling the
operating system to start a process. Any process must have some
executable from which the process is started. The only reason that the
CLI can map what looks like an executable file to a built-in command is
that the CLI is already running and can intercept that. But when starting
the process in the first place, there's no CLI running to do the mapping.
So an actual executable is required.

By explicitly specifying that the CLI is run ("cmd.exe"), then a command
can be passed to that CLI, and it's parsed just as it would have been had
the user typed it at the command prompt. Of course, replacing "date" with
"date.exe" in that case would result in the original behavior, assuming an
alternative "date.exe" was still installed, and if not would produce the
built-in "date" command.
[...]
Looks like not only is "date" a cmd.exe builtin, so is "date.exe"???
Looks
like a bug...
See above. The only reason that "date.exe" is a "built-in" is that it
matches in name with an existing built-in, and this is either by design,
or a very ancient, unnoticed, unresolved bug. If an actual date.exe had
been found in the path, that would be run instead.

Seems like reasonable behavior for the DOS CLI to me. But if you feel
it's a bug, I think you ought to report it to Microsoft. :)

Pete
Jun 25 '07 #8

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

Similar topics

4
by: Dan Rawson | last post by:
Is there any way to force getopt to process one option first?? I'd like to be able to pass in the name of a configuration file for my application, then have the remaining command-line parameters...
2
by: pyrexia | last post by:
Greets all. I'm attempting to write an app that will be used as a 'control/launcher' application for other apps. For the sake of argument let's say the app is launched from a command line: ...
8
by: Keith French | last post by:
I am trying to launch an external program within Visual Basic 2005 Express. If it is a simple program it works well with:- myProg = "C:\MyFolder\MyApp.exe"...
4
by: My SQL | last post by:
Hi Can I trigger an external program to run when a new record is added to the mysql table? The external program is in C and instead of scanning the table continuously for new insertions, it...
3
by: lookaround | last post by:
Hi everyone, I need some help... I call an external exe (a command-line tool) with Process.Start through this code: try { p = new Process(); p.StartInfo.UseShellExecute = false;...
1
by: =?Utf-8?B?Q3JhaWc=?= | last post by:
Hi Guys, I am trying to caputre the output for an external application. The idea is to use the System.Diagnostics.Process to run the exe in a process and redirect the output to a string. When...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
4
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a...
2
by: ellennolan | last post by:
Hello, I wonder if anyone can help with calling external shell script in c++. Basically, in the shellscript, I want to pass src, dst, md5. If the src's md5 matches md5 given, it will be link to...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.