Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28492 Discussions

Trouble defining stdout when starting application from Win API Shell function

Leigh_Wardle
Beginner
511 Views
Hi all,

I am trying to run my compiled application (compiled with IVF 11.1) via the Win API Shell function.

The command line that I use with the Shell function is something like:

"d:\AppPath\CIRCLY32.EXE" @ 1>"D:\DataPath\JobName.sto" 2>&1

The task executes OK, except that there is no stdout file ("D:\DataPath\JobName.sto") created.

If I run the same command line from a command prompt the correct stdout file is created.

I'm puzzled!!!

Regards,
Leigh
0 Kudos
6 Replies
DavidWhite
Valued Contributor II
511 Views
Quoting - Leigh Wardle
Hi all,

I am trying to run my compiled application (compiled with IVF 11.1) via the Win API Shell function.

The command line that I use with the Shell function is something like:

"d:AppPathCIRCLY32.EXE" @ 1>"D:DataPathJobName.sto" 2>&1

The task executes OK, except that there is no stdout file ("D:DataPathJobName.sto") created.

If I run the same command line from a command prompt the correct stdout file is created.

I'm puzzled!!!

Regards,
Leigh

You may want to try embedding this string in an additional set of quotes - sometimes the quote characters get stripped off and the string executed isn't what you expected.
0 Kudos
Leigh_Wardle
Beginner
511 Views
Quoting - David White

You may want to try embedding this string in an additional set of quotes - sometimes the quote characters get stripped off and the string executed isn't what you expected.

Thanks, David.

I tried embedding this string in an additional set of quotes.
But that made the Shell function return TaskID=0 - meaning the task did not start.

Regards,
Leigh
0 Kudos
IanH
Honored Contributor II
511 Views
Could you elaborate on "Win API Shell function". Are you referring to ShellExecute?

The redirection that you are chasing is normally performed by cmd.exe, hence it "works" from a command prompt. Perhaps the API that you are calling does not invoke your program via cmd.exe or perform its own redirection processing. Try something along the lines of:

cmd.exe /c "d:AppPathCIRCLY32.EXE" @ 1>"D:DataPathJobName.sto" 2>&1

as the program to invoke (perhaps cmd.exe as the file with the rest, including the /c, as the parameters, depending on the particular API you are calling). Comments about requiring additional quotes (particularly around your original command line) may apply here as well.

For light entertainment or further debugging, consider temporarily putting a call to the F2003 intrinsic GET_COMMAND in your program and writing the resulting command argument out to a file. If it contains the redirection bits then you know that the command line for your call is not being processed as you want by whatever api you are calling.


0 Kudos
Leigh_Wardle
Beginner
511 Views
Quoting - IanH
Could you elaborate on "Win API Shell function". Are you referring to ShellExecute?

The redirection that you are chasing is normally performed by cmd.exe, hence it "works" from a command prompt. Perhaps the API that you are calling does not invoke your program via cmd.exe or perform its own redirection processing. Try something along the lines of:

cmd.exe /c "d:AppPathCIRCLY32.EXE" @ 1>"D:DataPathJobName.sto" 2>&1

as the program to invoke (perhaps cmd.exe as the file with the rest, including the /c, as the parameters, depending on the particular API you are calling). Comments about requiring additional quotes (particularly around your original command line) may apply here as well.

For light entertainment or further debugging, consider temporarily putting a call to the F2003 intrinsic GET_COMMAND in your program and writing the resulting command argument out to a file. If it contains the redirection bits then you know that the command line for your call is not being processed as you want by whatever api you are calling.



Combining cmd.exe /c and additional quotes (underlined below) around my original command worked!

That is:

cmd.exe /c ""d:AppPathCIRCLY32.EXE" @ 1>"D:DataPathJobName.sto" 2>&1"

Many thanks to IanH and David White for your help.

Regards,
Leigh
0 Kudos
jimdempseyatthecove
Honored Contributor III
511 Views

Leigh,

As an extention to this, keep in the back of your mind that you can additionally use START. Start is particularly handy when you want to launch multiple concurrent processes.

Jim Dempsey
0 Kudos
Leigh_Wardle
Beginner
511 Views
Quoting - IanH
For light entertainment or further debugging, consider temporarily putting a call to the F2003 intrinsic GET_COMMAND in your program and writing the resulting command argument out to a file. If it contains the redirection bits then you know that the command line for your call is not being processed as you want by whatever api you are calling.



Just for the record, GET_COMMAND now returns "d:AppPathCIRCLY32.EXE" @
So it leaves off the redirection bits...
0 Kudos
Reply