What is the FORTRAN input statement (e.g., READ statement, or OPEN statement) to accept input from a mouse? For example, in Windows explorer, it is possible to right-click on a file and then select a FORTRAN executable from the menu that appears. How do I make such a FORTRAN program capture whatever the mouse sends (e.g., capture the name of the file, or whatever the mouse transmits)? Information out there about FORTRAN input seems restricted to input from a file or the keyboard. I cannot find anything about input from a mouse.
I've made progress on my own and, for those interested, here it is:
Firstly, the "fortran standard" does not directly support input from a mouse. But Windows Explorer can be made to pipe a file name into a fortran executable nevetheless.
Under Windows, the right-click generates the full \path\filename as a command line argument. That information can be captured by a fortran using "get_command_argument", as follows:
PROGRAM get_filename
CHARACTER(len=100) :: arg
CHARACTER(len=2000) :: filename
filename = ''
! NB: spaces in a file name define separate arguments, so re-assemble the file name as it comes in
i = 1
DO
CALL get_command_argument(i, arg)
IF (LEN_TRIM(arg) == 0) EXIT
filename = TRIM(filename)//' '//TRIM(arg) ! putting the spaces back in
i = i+1
END DO
WRITE (*,*) 'file= ',TRIM(filename)
read(*,*)
END PROGRAM
A link to the executable can be placed in the Windows right-click menu, as explained here:
http://www.howtogeek.com/107965/how-to-add-any-application-shortcut-to-windows-explorers-context-menu/
You need to add "%1" to the name of the executable to make it accept command line arguments,
e.g., I called my executable "PW_copy.exe", and so the final registry entry was: \path\PW_copy.exe %1
It works!
Dragging the mouse across several files generates separate threads each with a different file name.
Related
I'm using the Nintendo 64 emulator, Mupen64Plus.
It has a file called mupen64plus-ui-console.exe used to launch games through command-line. It also accepts keyboard shortcuts to perform commands, but it is limited.
Mupen64Plus Commands/Functions
This wiki page shows a list of all commands that can be called, I think from the mupen64plus.dll.
RUNDLL32
I read how to pass commands to a dll like this:
RUNDLL32.EXE <dllname>,<entrypoint> <optional arguments>
Calling a Command with RUNDLL32
I'm trying to call M64CMD_STATE_LOAD with cmd.exe, to load a save file.
Info from Wiki:
Command Functions Prototype m64p_error CoreDoCommand(m64p_command
Command, int ParamInt, void *ParamPtr)
ParamInt Ignored ParamPtr Pointer to string containing state file path
and name, or NULL
This command will attempt to load a saved state file. If ParamPtr is
not NULL, this function will load a state file from a full pathname
specified by this pointer. Otherwise (ParamPtr is NULL), it will load
from the current slot.
I have the Mupen64Plus emulator running a game. I then open cmd.exe and paste in this line.
RUNDLL32.EXE "C:\Path\To\mupen64plus.dll", CoreDoCommand M64CMD_STATE_LOAD 1 "C:\Path\To\MySave.m64p"
Problem
It accepts the command, I get no errors, but the save file isn't loaded.
Questions
Are the arguments being passed wrong?
Does the mupen64plus.dll not have hooks into the currently running mupen64plus-ui-console.exe?
Is it loading the save file into nothing?
Is it not possible to do it this way?
To run a CUDA C program we build the program and then run the binary file created from the command line as
/.prgm_bin_file
If for example the program needs some input files like for programs to image processing, I want to supply the data files or the input files at the time of compilation.
How can I do that. How the above command can be edited to give the required files.
Thanks in advance.
If your program opens data files to use for input, it's using some file I/O API to do so. For example, one possible method is to use fopen.
Just to use it as an example, if you are using fopen, it expects a filename (a character string) passed as the first parameter.
Many programs will take this filename from a the command line used to invoke the program. But there's nothing that would prevent you from hard-coding the filename:
fp=fopen("mydata", "r");
In that case, the program would always attempt to open the file mydata
But if your program is already designed to use the filename as a command line parameter, it's not clear that this is any more useful than just invoking your program that way:
./prgm_bin_file mydata
I have a set of files with a common file extension, e.g. *.EXT.
These files are located in different folders on my PC.
I have a cmd script "Script.bat", located in C:/foo/ folder
I've set an "Open with..." file association for the *.EXT files to be opened by this "Script.bat" CMD script.
The questions is:
which variable do I have to use to designate the filename and the location of the doubleclicked EXT file within the script.
The associated application, in your case your batch file, will be called with the "double clicked" file as the first command line argument. Thus, the fully qualified filename to that file (including the "location") will be available in %1.
Example (sort of):
#echo off
REM assuming this is your "Script.bat"
echo You double clicked on "%~1"
Note that using %~1 instead of simply %1 removes enclosing quotes, which have been automatically added by Windows when it called your application (batch file).
For example, Windows will call it like you would have entered it in CMD.EXE like this:
Script.bat "C:\Wherever it is\file.ext"
To extract individual parts you have a couple of options:
echo Filename only: %~n1
echo Filename and extension: %~nx1
echo Drive and directory only: %~dp1
For a complete list of possibilities enter FOR /? on the prompt and page all the way to the end (mentally replace "%I" by "%1" for your example).
Can anybody tell me how I can paste text input into the Dev-C++ console (command line shell) while running a program in Dev-C++?
Also is there any other simple IDE which allows users to work with a single source file w/o creating a project?
af far as i can remember dev-cpp start a windows commadline window when a consol application is started. so if you have somethig like
cout << "enter a char: ";
cin >> c;
in your code, the consol window will be wating for input.
an to your second question: Yes and No
Yes: you can use g++.exe (witch comes with dev-cpp) and notepade.exe (witch comses with windows)
and compile your source using commad g++.exe source.cpp and run you application by typing a.exe in a console window witch you have to open yourself and navigate to the directory where source.cpp is located.
No: (g++.exe + notepade.exe) == IDE
Note that you have to extend the PATH envirenment variable to be able to use g++.exe without fullpath to it
I came across this piece of batch code. It should find the path to every single .exe file if you enter it.
#Set Which=%~$PATH:1
#if "%Which%"=="" ( echo %1 not found in path ) else ( echo %Which% )
For instance, if you save this code in the file which.bat and then go to its directory in DOS, you can write
which notepad.exe
The result will be: C:\WINDOWS\System32\notepad.exe
But it's a bit limited in that it can't find other executables. I've done a bit of batch, but I don't see how I can edit this code so that it can crawl the hard drive and return the exact path.
When you want to find an executable (or other file) anywhere on the drive, not just in PATH, then perhaps only the following will work reliably:
dir /s /b \*%!~x1 | findstr "%1"
But still, it's horribly slow. And it doesn't work with cyclic directory structures. And it probably eats children.
You may be much better off using either Windows Search (dependin on OS) or writing a program from scratch which does exactly what you want (the cyclic dir thing might happen on recent Windows versions pretty easily; afaik they have that already by default).
Here's the same thing written in python:
import os
def which(program,additional_dirs=[]):
path = os.environ["PATH"]
path_components = path.split(":")
path_components.extend(additional_dirs)
for item in path_components:
location = os.path.join(item,program)
if os.path.exists(location):
return location
return None
If called with just an argument, this will only search the path. If called with two arguments ( the second being an array ), other directories will be searched.Here are some snippets :
# this will search notepad.exe in the PATH variable
print which("notepad.exe")
# this will search whatever.exe in PATH. If not found there,
# it will continue searching in the D:\ drive and in the Program Files
print which("whatever.exe",["D:/","C:/Program Files"])