• C

Add Parameter To Command-Line Program

There's a Excel converter that was written by a third-party (but source code is available) that I need a new parameter added to it.  I just need to be able to specify an output file and directory and have it write to that file.  Right now it just shows to the screen.  I know I can use the greater sign to capture the output to any file but I need the actual program to write the output to a file.

Can someone here do that?

The source code is at: http://chicago.sourceforge.net/xlhtml/

(I need an output parameter for both the xlhtml.exe and ppthtml.exe)
dokkenAsked:
Who is Participating?
 
moduloCommented:
PAQed, with points refunded (500)

modulo
Community Support Moderator
0
 
andrewjbCommented:
Just create yourself a .bat file... something like

xlthml.bat:

xlhtml.exe > %%1


c'est ca! ?



0
 
ankuratvbCommented:
Hi,

I'll try to open the source if i get time but this u can do on ur own as well.
Look for a line similar to this:

set f [open "/tmp/myfile" "w"]

This opens a file for writing
All u have to do is replace the "/tmp/myfile" string with "$str"
where $str is a variable containing the string from the command line

set f [open "$str" "w"]

Here f is the name of the file pointer similar to FILE *f; in C
so the name of the pointer may be different in the source

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dokkenAuthor Commented:
Unfortunately, I can't do it with a bat file.  I'm calling this from a Windows Service and it ALWAYS returns a blank file.  It works fine if I call it from a normal app (using the exact same code).  It appears to be due to the capture since other converters work fine (the ones that write to a file themselves).
0
 
ankuratvbCommented:
Here is how to access and manipulate command line arguments:
http://www.iona.com/support/docs/orbix2000/2.0/codegen/html/ConfigGenie2.html
0
 
jkrCommented:
>>I'm calling this from a Windows Service and it ALWAYS returns a blank file

Are spawning it like

cmd.exe /c xlhtml.exe > file.txt

?

Without using the shell (cmd), there will be no output redirection at all, since the shell does that, not the program.

0
 
ankuratvbCommented:
If u want to change the code,it will be a very long drawn out process.
Why because cuurently the program only prints to screen.
U'll have to change wherever there is a line to output something on screen to write it
to a file.and there will be plenty such lines to change.

Do u think it will be worth the effort?
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi dokken,

I downloaded the source code and looked through it.  (It's fairly ugly....)  The source code includes several programs.  Are you going to make these changes to all of the programs or just a select few (one)?  Several thoughts come to mind...

1)  Include the new "global" variable "FILE *output".  Convert all of the print(), puts(), putc(), putchar(), etc functions to be "fprintf (output)", fputs (" ", output), etc.  The first line in main will be "output = stdout;".  If an extra parameter is given on the command line you can then "output fopen (argv[argnum], "w");" to write to that file.

2)  Similar to the previous step, use freopen() to redirect stdout to a file.

3)  Write a small C program to wrap the converter.  Your service will then call your wrapper which will execute the converter by calling system() and redirecting the output.


I'm partial to number 3.  It allows you to do what you want without actually changing the converter.  When updates to the converter are made available, you'll be able to reinstall it by simply recompling -- no modification should be necessary.



Good Luck,
Kent
0
 
ankuratvbCommented:
Sorry,i thought the code is in TCL so please ignore my first two comments.
0
 
jkrCommented:
>> Include the new "global" variable "FILE *output".  Convert all of the print(), puts(), putc()

IMHO "cmd.exe /c xlhtml.exe > file.txt" might be a *tad* bit less complicated :o)
0
 
dokkenAuthor Commented:
jkr: The code I'm using is VB.NET and I'm using System.Diagnostics.ProcessStartInfo.  This does work from a normal application, just not from the Windows Service.

ankuratvb: I need to use the converter so it doesn't matter how much work it requires (by myself or someone here or if I have to pay someone).

Kent: The only two files that I will be using are the xlhtml.exe and ppthtml.exe.  I don't know C so #3 won't really work for me.  I did something similar in a command line VB.NET program but it also returned a blank page when called from the Windows Service (worked fine when called directly from a DOS window).
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi jkr,

>> IMHO "cmd.exe /c xlhtml.exe > file.txt" might be a *tad* bit less complicated :o)

Notice that I made him read the "Wow this looks like a lot of work" answer before the two "rational" ones?

Now can someone explain to me why my wife continues to claim that I drive her nuts????   ;-)

Kent
0
 
jkrCommented:
>>This does work from a normal application, just not from the Windows Service.

That's a different thing - start the application with this exact command line

"cmd.exe /c xlhtml.exe > file.txt"

and it will work.
0
 
dokkenAuthor Commented:
jkr: I've tried two different methods, with that being one of them.
0
 
jkrCommented:
And where have you looked for the file? It should reside in %WINDIR%\system32
0
 
dokkenAuthor Commented:
No, because I specify the full path name as the filename.  The file is created but is empty.
0
 
jkrCommented:
Hmm, another idea - try

"cmd.exe /c xlhtml.exe 2>&1 file.txt"
0
 
dokkenAuthor Commented:
I got it working using System.Diagnostics.ProcessStartInfo.  Thanks everyone for help... it looks like I won't be needing to modify the converters after all.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.