Command line parameter question

my program needs to read command line parameters.
So i am using paramstr to get the values , however i have a small problem when command line contains the character > or |
This problem only comes when i call my program though a batch file , if i type the same command through START-RUN option then it works fine.
anything after those characters is lost
example if command line is
 myexe.exe hello there
then program reads hello there correctly
however if it is
myexe.exe hello > there
 then program reads only hello , it seems it looses > there
can anyone help me with this one ?I want to get entire command line
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You will likely need to surround your parameters in quotes due to the fact that the symbols that are causing you problems are piping symbols used to redirect the output of your program.  Put the parameters in quotes and it should ignore those symbols.
try :
myexe.exe ">" "senod param"
in your batch
sorry devguru, didn't refresh my webbrowser

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

earlrainerAuthor Commented:
hi guys,
actually i am trying to make a small program that will replace an old program .
now the old program is used in hundreds of batchfiles and strangely it works fine with those characters.
am not sure what that program is made in ,maybe C++ .
so was just wondering if that program works without using " ,how come my program cannot detect those characters.
am only trying to avoid changing all those batchfiles.
thank you for your help so far
Steve KnightIT ConsultancyCommented:
If you send a commandline to it from a batch file with > characters in then it will redirect output to the filename after that, period.  Could it be that the old program isn't reading that parameter but is actually just outputting to the console and the > whatever is creating a file called whatever that is then used somewhere else?

If you understand all about redirection using > < >> << | 2> 2>> etc. then sorry, ask if you want to know more!
Steve KnightIT ConsultancyCommented:
i.e. do your batch files do does stuff like this?

myexe.exe hello > afirstfile.txt
myexe.exe something else  > anotherfile.txt

then processing output that is in afirstfile.txt and anotherfile.txt
Steve KnightIT ConsultancyCommented:
Don't know why I am bothering answering anyway because I followed a link from the MSDOS area but of course on this stupid website this is really in Delphi, points no use to me here!
as dragon-it posted > redirects program out and you can't help it and there's no magic in it it doesn't matter if it was written in c or in any other language

try this:

program Project1;
  WriteLn(OutPut, 'hello world');

and then run in from command line: Project1.exe > test.txt

it will create test.txt file and put single line "hello world" in it.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
earlrainerAuthor Commented:
Hi guys ,
thanks once again for spending time to help me.
I understand what you guys are trying to say but there is one thing wrong with what you are saying.

if i have a batch file and I put something like
myexe.exe hello > afirstfile.txt
myexe.exe hello > asecondfile.txt

there is no way the program can redirect data to afirstfile.txt and then read it because it just cant read anything after > so it does not know which file to redirect to and then read ,which is the exact problem i am stuck with.

I hope I am not confusing you guys

Thank you once again for your valuable time


Most of the characters are readable if you first surround them with double quotes:
  Prog.bat     "C:\File.txt"
  Bat.cmd       "Program.exe/s MyFile.dat  > Output.txt"

Everything inside of the quotes is a part of the same argument and can be passed as a complete string

> myexe.exe hello > there

the word "there" is translated into the filename for your output via redirection

>  it seems it looses > there

not lost, it is interpreted for you for execution
earlrainerAuthor Commented:
just in case this helps ,
the freeware program i am trying to imitate is here

it works with > in batch files , very amazing indeed
> I hope I am not confusing you guys

I am

I doubt you need:

MyExe  >   Log.txt
MyExe  >> Log.txt

Try this as a batch file:

echo hi >     Hi.txt
echo hi2 >   Hi.txt
echo hi3 >> Hi.txt

This is appending, which is similar to have read original file before adding to it
You also want input?
From a file?
From the keyboard?
>>there is no way the program can redirect data to afirstfile.txt and then read it because it just cant read anything after > 

see my example again, can you see there somwhere checking params or lookng for file name?

>>the freeware program i am trying to imitate is here

didn't download file well I think I don't have to....
Winput "SET Name=$input" "Please enter your name" > temp.bat
if not errorlevel 1 call temp.bat

This will send a set statement to the file temp.bat,(...)"

as you can see here's everything we told you,  you have parameters in quotes and REDIRECTED output to temp.bat "This will send a set statement to the file temp.bat"

earlrainerAuthor Commented:
 Thank you very much for your help , it worked perfectly fine .
i am sorry I was dumb to understand your solution earlier.
Thanks a lot

earlrainerAuthor Commented:
Thank you so much , this had me confused for so long
glad I could help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.