Solved

Add Parameter To Command-Line Program

Posted on 2004-03-26
19
205 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
  • 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
 
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:Kdo
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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:Kdo
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now