I have a .exe file that I have built from the makefile of a set of source .cpp files.
It should take in a set of inputs and write the output to a .txt file. The manual I am following provides the following instruction for running it on linux:
./xyz -l4 -w6 -k4 -iSampleInputTJU.txt -oMyOutputFile.txt -p
But I need to run it on windows 10. So I typed in:
C:>\Desktop\xyz -l4 -w6 -k4 -iSampleInputTJU.txt -oMyOutputFile.txt -p
However it tells me that it cannot open the input file.
I am not sure what I am doing wrong. Please help. Any input will be appreciated.
To execute a program, regardless of platform. The format shall be:
<Program path> [program arg list]
The path can be relative or absolute.
In your Linux shell. You are running:
./xyz -l4 -w6 -k4 -iSampleInputTJU.txt -oMyOutputFile.txt -p
You are using ./. This means your program is under current directory.
In your windows console:
C:>\Desktop\xyz -l4 -w6 -k4 -iSampleInputTJU.txt -oMyOutputFile.txt -p
You are using absolute path here. You might not run the program under the path which your input file locates. You can type dir to check the current directory see if the input file is there.
Related
https://github.com/ninja-build/ninja/releases
I have downloaded the ninja-win.zip folder and extracted it. When I open it, there is a single .exe file in the entire folder. When I double click it a cmd window flashes for a split second. I have also tried running it as administrator, but the same thing happens. What I don't understand is, what am I expected to do with this .exe file?
You must open a terminal (cmd.exe on Windows) and type something like ninja -f /path/to/buld/file. You may also wish to modify the PATH environment variable so that Windows knows where to find the Ninja executable, depending on your setup.
You can simple download ninja.exe file from this Link
https://github.com/ninja-build/ninja/releases
After that you just have to add the path to your ninja.exe file to your windows environment variables and then you can use ninja commands from anywhere in windows.
1. Open cmd in your Project Directory
2. There are guides on the internet on where to save the Ninja.exe so that it'll be callable in Cmd without specifying directory. Either follow them or:
i, Specify Directory when Calling Ninja. Putting "ninja" in Cmd actually calls Ninja.exe and is the same as something like "C:\users\user1\downloads\Ninja". or:
ii, Save Ninja.exe in the same directory as Project.
3. proceed with rest of the command.
Therefore the Final Command would be:
"C:\users\user\downloads\Ninja.exe" -f "D:\Projects\Project1"
Suppose that I add a program to path that is dependent on a file name "test.in". I programmed this in C++ so I used ifstream fin("test.in") without specifying the directory. Now if I were to run this program from a different directory, would the program be able to access the file "test.in"?
Firstly, this has nothing to do with the file extension, which is merely a convention given as part of the filename.
Secondly, you were always using a relative path. Even when you were running your program "from the same directory" as test.in, you were reliant on the "working directory" of your shell context being the same as the directory in which the executable and the file reside.
This is not always the case.
For example:
~/myProject:# ls
test.in
program
~/myProject:# ./program
This is okay, because your shell is at ~/myProject, and so is test.in.
However, if you'd written:
~/myProject:# cd ..
~:# ./myProject/program
…then your test.in file wouldn't be found, as it does not exist in ~. It exists in ~/myProject. It doesn't matter that the executable itself is also found in ~/myProject.
This is actually desirable behaviour, as it allows flexibility from the shell. Ideally you would allow support for piping/redirecting the file to the process instead (program < test.in — now there are no assumptions baked into your code at all!), but we can save that for another day.
For now, you seem to be concerned about what happens if you move the executable away. Don't worry: just use this feature!
~:# mv myProject/program .
~:# cd myProject
~/myProject:# ../myProject
Your working directory is the directory in which test.in resides, so it will be found via the relative path given in your program code.
I am writing a small shell script that launches a program in my wine directory.
My challenge is that I have installed this on multiple machines, some with 64
and some with 32 bit, some with English and some with Norwegian locals.
the name of the program files directory in $HOME/.wine/drive_c can thus change
from Program Files, Program Files (x86), programfiler etc..
The bash line I have so far is this:
(cd $HOME/.wine/drive_c/[Pp]rogram*/... ; wine ...)
However, the [Pp]rogram* line does not work, does anyone have a good suggestion?
That should work just fine, but since you will have both Program Files and Program Files (x86) on 64 bit installations this will always expand to Program Files which might be wrong in your case.
I would use the following to dynamically determine the correct path:
look_for='My Program/myprogram.exe'
for dir in "$HOME"/.wine/drive_c/[Pp]rogram*[Ff]*/; do
if [ -e "${dir}${look_for}" ]; then
cd "${dir}"
wine [...]
exit $?
fi
done
This loops over all possible "program files" directories and checks if the file/directory specified in $look_for exists underneath it. If it does, it takes the directory component of $look_for, cds into it and runs wine from there.
When I indicate a file to create and write to via ofstream without a path or drive letter, i.e. "testfile.txt" where is it placed when NOT run in an IDE (when run in VS, the file is placed in the project working directory) and run from a shortcut (I needed to indicate command line arguments)? It does not place it in the same location as the executable when run from a shortcut.
Your shortcut has a "Start in" property, which is the directory where your files will be placed by default (i.e. if you don't specify a path). The main exception is that in Vista, if the directory is in \Program Files\ the actual writes will be redirected to your profile directory.
If you start the program from the command prompt, the default directory is the working directory (i.e. your CMD.EXE prompt when you started your program). This isn't necessarily where your program is located. If your program is on the %PATH% or if you specified a full path to your executable, CMD can run your executable even if is stored outside your current working directory.
I'm trying to figure out where to save multiple .txt files so that i can have a command line tool project in Xcode read directly in from them while running it.
I understand that Xcode compiles everything to a folder, DerivedData, which i have saved in the same location as my source code for each project respectively.
can i save multiple .txt files anywhere in the DerivedData folder or include it in the build settings and phases so that when i run the command line tool i can type the name of a file, it will read in from that file.
By default the compiled/linked binary will look into its own directory for files.
For example, my binaries are at ProjectName/Build/Products/Debug/ and therefore it will look for files from that dir.
You can use relative path from that folder to the outside.
Or, you can create a symbolic link to another directory (on Terminal):
ln -s source_dir target_file
target_file must be located in the same directory as your binary. And you can reference the other files like "target_file/file1.txt", etc.