- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I am trying to transfer some command line arguments between a c++ program launching a fortran exe. For some reason, theCOMMAND_ARGUMENT_COUNT command always return zero, altough I do have some arguments transfered. If I call theget_command_argument routine, at index zero, I get the answer I am looking for (in debug). The problem comes from the fact that the behavior of the command line arguments seems to vary depending if I am compiling debug or release. Here is the Fortran code I am using:
integer nArgumentCounts
character strTempPath*300
nArgumentCounts = COMMAND_ARGUMENT_COUNT()
write (*,*) "Command line argument Counts is: ", nArgumentCounts
call get_command_argument(0, strTempPath,len,status)
write (*,*) "Command line argument Original is: ", strTempPath
So,nArgumentCounts is always zero, but, the call toget_command_argument(0,...) returns either the path and name of this exe (in release) or the real argument I am transfering from my C++ app.
Here is the C++ calling code:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWMINIMIZED;
char temp[300];
sprintf(temp,"\\"%s\\"",m_strTempDir);
// Start the child process.
if( !CreateProcess( strFESTAN,
temp, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
π ) // Pointer to PROCESS_INFORMATION structure.
)
Why do I get this behaviour ? What am I doing wrong ?
For information, here is the Fortran version I am using:
Intel Visual Fortran Composer XE 2011 Integration for Microsoft Visual Studio* 2010, 12.0.3471.2010
Thank you
Philippe
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried your code on an Fortran 10.0.25 on W7x64 and got similar results. I had to change to tchar as using char required CreateProcessA and .... I think it may not act quite like a command line program in that
If both lpApplicationName and lpCommandLine are non-NULL, the null-terminated string pointed to by lpApplicationName specifies the module to execute, and the null-terminated string pointed to by lpCommandLine specifies the command line. The new process can use GetCommandLine to retrieve the entire command line. Console processes written in C can use the argc and argv arguments to parse the command line. Because argv[0] is the module name, C programmers generally repeat the module name as the first token in the command line.
The quoted command line you had would be necessay as you had it for any internal spaces, and each arg
I tried Release as well, changing path from Debug to Release and got the same results.
[cpp]#include "stdafx.h" #include "windows.h" int _tmain(int argc, _TCHAR* argv[]) { STARTUPINFOW si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags |= STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOWMINIMIZED; wchar_t temp[300]; wchar_t * m_strTempDir = L"this "someplace odd""; wchar_t * strFESTAN = L"c:\c\05\fx\fx\Debug\fx.exe"; _stprintf(temp,L"%s %s",strFESTAN, m_strTempDir); // Start the child process. if( !CreateProcess( NULL,//strFESTAN,//strFESTAN, temp, // temp, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. π ) // Pointer to PROCESS_INFORMATION structure. ) return 0; }
If both lpApplicationName and lpCommandLine are non-NULL, the null-terminated string pointed to by lpApplicationName specifies the module to execute, and the null-terminated string pointed to by lpCommandLine specifies the command line. The new process can use GetCommandLine to retrieve the entire command line. Console processes written in C can use the argc and argv arguments to parse the command line. Because argv[0] is the module name, C programmers generally repeat the module name as the first token in the command line.
The quoted command line you had would be necessay as you had it for any internal spaces, and each arg
I tried Release as well, changing path from Debug to Release and got the same results.
[cpp]#include "stdafx.h" #include "windows.h" int _tmain(int argc, _TCHAR* argv[]) { STARTUPINFOW si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags |= STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOWMINIMIZED; wchar_t temp[300]; wchar_t * m_strTempDir = L"this "someplace odd""; wchar_t * strFESTAN = L"c:\c\05\fx\fx\Debug\fx.exe"; _stprintf(temp,L"%s %s",strFESTAN, m_strTempDir); // Start the child process. if( !CreateProcess( NULL,//strFESTAN,//strFESTAN, temp, // temp, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. π ) // Pointer to PROCESS_INFORMATION structure. ) return 0; }
program fx implicit none ! Variables integer nArgumentCounts character strTempPath*300 integer len integer status integer indx ! Body of fx call system("pause")! pause nArgumentCounts = COMMAND_ARGUMENT_COUNT() write (*,*) "Command line argument Counts is: ", nArgumentCounts do indx=0,nArgumentCounts,1 call get_command_argument(indx, strTempPath,len,status) write (*,*) "Command line argument Count is: ", indx, " is: ",trim(strTempPath) enddo call system("pause") end program fx [/cpp]

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page