- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried 'SYSTEM' and 'SYSTEMQQ' - they both execute the command correctly but flash the console.
I also tried 'createProcess' - it does not seem to execute the command at all (though, for running EXE files I succesfully use 'createProcess' to run them with the 'SW_HIDE' option)
Any ideas?
thanks in advance.
dmitri
Link Copied
- 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
Is it possible to execute system commands (eg, 'rename "file1" "file2"') without having the system console
...
I also tried 'createProcess' - it does not seem to execute the command at all (though, for running EXE files I succesfully use 'createProcess' to run
them with the 'SW_HIDE' option)
Any ideas?
In a similarcase I use an additional Bat-file and a 'CreateProcess' Win32 API function successfully executes it.
The Bat-file looks like:
...
@echo off
attrib -R ..\Include\*.h > nul
copy Stdphf.h ..\Include\*.h > nul
attrib +R ..\Include\Stdphf.h > nul
attrib -R ..\..\Include\*.h > nul
attrib -R ..\..\Include\*.cfg > nul
copy Set.cfg ..\..\Include\*.cfg > nul
copy Test.cfg ..\..\Include\*.cfg > nul
copy Algorithm.cfg ..\..\Include\*.cfg > nul
copy AlgorithmSet.h ..\..\Include\*.h > nul
...
And in order to hide a console windowa 'STARTUPINFO' structureis used with the 'CreateProcess' Win32 API function.
A Bat-file based solution allows to isolate codes from some external operations and there is no need to re-compile
the source codes if something needs to be changed.
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In my case, the names of the files (and the command to be executed) could be changing, so I guess instead of just constructing a different command on the fly in Fortran I would need to write some code that writes the bat-files?
Steve - is there an example of using shellExecute to run system commands? I quite routinely use it to for things like opening files in notepad etc (based on your great examples!), but I have never been able to use it for system commands.
Say, for the previous example of the 'rename file1.txt file2.txt': I tried passing this as the filename input into shellexecute but got return code = 2 from shellexecute. I also tried using 'file1.txt file2.txt' as the parameters, with no luck either .. Is there a general approach for system commands such as these?
** I also tried shellExecute(filename='path/cmd.exe',params='rename "file1" "file2"' etc) but this did not work either (Retcode indicated success but the rename command was not executed). Adding full paths to the files didnt work.
any hints?
thanks
dmitri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Say, for the previous example of the 'rename file1.txt file2.txt': I tried passing this as the filename input into shellexecute but
got return code = 2 from shellexecute. I also tried using 'file1.txt file2.txt' as the
[SergeyK] Here isa descriptionof the error code 2:
The system cannot find the file specified (ERROR_FILE_NOT_FOUND ).
parameters, with no luck either .. Is there a general approach for system commands such as these?
...
any hints?
thanks
dmitri
I use relative paths inmyBat-file and itis executed froma strictly specifiedfolder. I remember that I had lots
of problems related to attempts to executecommands from a"wrong" folder.I think that absolute paths to some files or
commands could be used instead.
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have a close look at the command line syntax of cmd.exe. You probably need to have parameters of
/c ren file1 file2
Batch files are fragile. If you are just renaming a file then use the Windows API as already mentioned, or the RenameFileQQ IFPORT portability function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for the help. I understand that the API's are often preferable, and I already use them here and there within the limits of my understanding.
But sometimes I just want to quickly run a system command without working out API's etc - using which cannot be constructed 'on-the-fly' in the same way as system command strings such as above.
What I didnt realise - and paid for handsomely in confusion - was that calling CMD.EXE has different syntax for the same command than the DOS shell... slightly inconvenient I guess but at least its still a string :-)
thanks again!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page