Highlighted
Absent Member.
Absent Member.
533 views

[archive] Starting a program by executing a file that is associated with it

[Migrated content. Thread originally posted on 19 September 2007]

Hello all,

I am trying to transfer a file through the C$COPY command and then have it opened in the appropriate associated program. I do not necessarily know the actual program that is being called.

For example, I am trying to open a PDF file in the appropriate program by doing the following:

[INDENT]
call "C$COPY" using "sample.pdf" "@[DISPLAY]:C:\SAMPLE.PDF" giving return-status.
call "C$SYSTEM" using "C:\SAMPLE.PDF", 129 giving return-status.
[/INDENT]

The file transfers properly but does not start the program, in this case Adobe reader. I get a return-status of "95".

Typing "C:\SAMPLE.PDF" from the command prompt (any directory) works fine. Typing the same thing in the Start -> Run box does likewise.

I suspect I am missing something really basic - possibly the switch in the "C$SYSTEM" call or maybe I should preface the file name with something like "start "?

Any help would be greatly appreciated.
0 Likes
7 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

I may have a solution to my above problem. It looks like I can call a BAT file that runs the file name. That seems to solve the problem.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

As you suspected, you should also be able to accomplish this by using "start C:\SAMPLE.PDF" as your C$SYSTEM call as well.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

Thanks for the reply. I'm pretty sure I tried that among the various different things I attempted. It's starting to get hazy now. The batch file was the only thing that worked. I suspect that C$SYSTEM does not honor associations made in the o/s.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

C$SYSTEM is executing a process, not the command shell, which is why it fails. When you execute a batch file, you are invoking the command shell, which has the association. This is why it works with the batch file.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

That makes perfect sense. Thanks.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

Check out the flag option in the documentation for the C$System routine. If you add 64 to the value, the command will be processed by the hosts command line processor. We open various types of files this way. I recommend using a value of 201 and preceeding your file name with "Start ". I think if you do not use the start you end up with an extra command window open until you close the file that you are accessing.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Starting a program by executing a file that is associated with it

Awesome! That worked wonderfully!

I used "200" as my flag. "201" continued the cobol program and left the desired application in the background. Due to the nature of what I am doing, the "200" flag seems more appropriate.

Thank you so much. Writing and copying a batch file really was not elegant.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.