Solved

Add Parameter To Command-Line Program

Posted on 2004-03-26
19
212 Views
Last Modified: 2010-08-05
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)
0
Comment
Question by:dokken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
  • +3
19 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 10689199
Just create yourself a .bat file... something like

xlthml.bat:

xlhtml.exe > %%1


c'est ca! ?



0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10689299
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
 

Author Comment

by:dokken
ID: 10689376
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:ankuratvb
ID: 10689378
Here is how to access and manipulate command line arguments:
http://www.iona.com/support/docs/orbix2000/2.0/codegen/html/ConfigGenie2.html
0
 
LVL 86

Expert Comment

by:jkr
ID: 10689500
>>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
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10689689
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10689707
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
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10689801
Sorry,i thought the code is in TCL so please ignore my first two comments.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10689825
>> 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
 

Author Comment

by:dokken
ID: 10689850
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10689876
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
 
LVL 86

Expert Comment

by:jkr
ID: 10689924
>>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
 

Author Comment

by:dokken
ID: 10690017
jkr: I've tried two different methods, with that being one of them.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10690042
And where have you looked for the file? It should reside in %WINDIR%\system32
0
 

Author Comment

by:dokken
ID: 10690071
No, because I specify the full path name as the filename.  The file is created but is empty.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10690163
Hmm, another idea - try

"cmd.exe /c xlhtml.exe 2>&1 file.txt"
0
 

Author Comment

by:dokken
ID: 10690165
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11460580
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question