I am having problem referring to the file path in Windows XP (SP2). Actually I want to run an exe file from a specified path say "C:\users\rakesh\Documents and settings\myexe.exe" in my program...I am using the function _wsystem("C:\users\rakesh\Documents and settings\myexe.exe") to run the file..
The problem is that it is not recognizing the space, so I went through some articles and I found an solution for that. I tried using the solution below ..it worked great:
C:\\users\\rakesh\\Docume~1\\myexe.exe
in the above after the first 6 chars I used "~1" to accomplish the rest...but it's not working when exe name is with space like below:
C:\\users\\rakesh\\Docume~1\\my exe.exe
and also I can't replace them with "~1"(not working for exe name).
How do you execute programs when there are spaces in the path or executable file name?
Just like on the command line, the spaces need to be inside double quotes:
_wsystem ("\"C:/users/rakesh/Documents and settings/myexe.exe\"");
Note that forward slashes work just fine for path delimiters.
Related
First off I would like to say I've seen the previous questions on this site, I've tried every solution but none fit my use case or solves my problem.
I am having trouble with the g++ complier being recognized, I've included this path:
C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe
which is where the current version of mingw is located (recently downloaded). I've also tried other options like changing the path to gcc.exe, and just regular bin. Someone please provide a detailed solution to this problem.
Other things i have tried and looked at closely would be:
http://stephencoakley.com/2015/01/21/guide-setting-up-a-simple-c-development-environment-on-windows
seeing as though I'm working through sublime text 3
Another thing Ive tried:
Ive tried to copy and paste the path into cmd and run it , but i find this error code:
C:\Users\Kxrk>C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
So seeing that, i tried another way , and that is to drag the file and drop it into cmd and get this :
C:\Users\Kxrk>C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe
g++.exe: fatal error no input files
compilation terminated
when u drag and drop the file it has double quotes around it , so i tried editing the path to contain double quotes around it and the path automaticlly changes back after saving.
This was very simple , it was one of those weird cases.
To solve my problem what i did was:
1: uninstall , the current version of the mingw compiler , because i felt as though the one i had was corrupt in a way.
2:Redownloaded it the compiler from the website http://www.mingw.org/
3: set up the new Environmental variable where i save it , witch was C:\MinGW\bin
I had to install g++ from the command line(cmd ,command prompt)
by using this command mingw-get install g++witch is located inside bin on default
now i created one more directory in the environmental variables , C:\MinGW\bin\g++.exe
6.Now everything works , and is normal
If you are trying to run the compiler from the command line then you have to put double quotes around the path, because the path contains two whitespaces (this is the reason for the first error).
The reason for second error is that you didn't specify which C++ program you want to compile. You have to append the filename of your C++ input file to your command:
C:\Users\Kxrk>"C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\g++.exe" program.cpp
See Barmak Shemiranis answer if don't want to enter the full path all the time. After that you can just use this:
C:\Users\Kxrk>g++ program.cpp
You have to use quotation marks around the path so that is treated as a single path:
c:\>"c:\program files\path\g++.exe"
A better way is to set the environment variables. Open Environment variables windows (in Windows 10 you can type in "environment variables" in search box) or right click on "Computer" in desktop, open "Advanced System Settings" and find the button for "Environment variables"
Go to your command propmpt, type set path, it will show list of directories, copy them,
Now type set path=<data you copied> and then add a semicolon and possible directory to g++ usually C:\MinGW\bin
I have problem when I try to compile my project in Code Blocks with wxWidgets, I was looking everywhere solution for my problem but nothing was good for me and nowhere was explained how to solve this problem...
I post image of my problem here http://postimage.org/image/ngejv16d3/
Agree with greatwolf. Or you can use DOS path instead (in command prompt go to C:\ and execute dir /x, it will display the DOS version of Program Files (x86) folder (without spaces). Then you can change your wx path accordingly.
The fully qualified path of your wxWidget location is getting truncated, most likely due to spaces in the path. Two possible ways to fix it, you can move your wxWidget install to another directory with the spaces removed or you can try enclosing your current path in "" double quotes when it gets passed to the compiler.
My goal is to build a program that renames all files in the current working directory so they don't have any spaces, any special characters or any accented characters (for example É would become E). I'm planning on using int rename(const char *oldname, const char *newname); . My problem is how do I get the files in the current working directory? I would like to have the executable I'm creating put in a folder with a files with bad names and run it and the files all be renamed.
A platform independent solution would be preferable, otherwise I'm using Windows 7 Enterprise 32bit.
This question isn't a duplicate because I don't know the path for opendir ("c:\\src\\"); it's whatever directory the program is being executed from.
Here's a sample code to do that:
http://bytes.com/topic/c/answers/869208-list-files-directory
In essence you utilize these APIs: FindFirstFile and FindNextFile
For cross-platform solution see findfirst() and findnext()
An option is to use opendir(".") , this will open the current directory.
I am have a trouble in using fopen() with relative path. I wanted to use fopen like this:
fopen("\\Saurabh\\pqrs.txt");
i am getting filePointer as null.
The situation arose because I am trying to create a setup or deployment project which has to read files. The file paths chosen by default after user executes setup are C:\Program Files\Setup..
(where exe is dumped). So I dumped the files in the same folder and gave path(fixed path or hardcoded) to those files in the program.
If the user selects some other path for installation, the program fails.
Is there any way I can fix this?
Two problems:
You need to escape the backslash character. Write \\.
You need to use a relative path. By starting a path with \\ you mean start from the root directory.
Putting these together, I think you should write:
fopen("Saurabh\\pqrs.txt");
Make sure you double up the \ characters. The string you're passing in should be "Saurabh\\pqrs.txt". Note that beginning a path with \\ means that it's not relative. (Well, actually it's relative to your current drive, but I doubt that's what you're looking for.)
I'm teaching myself some Django tonight using the local dev package at instantdjango.com
I made it through half the tutorial, building a basic map with points on it, then closed out of the console for a bit. I just fired it back up and now when I try to use notepad++ to edit files, console tells me it doesn't recognize the command. What happened?
When I as working through the first half, I was able to type: "notepad++ filename.ext" and I'd get a text editor that would pop up.
Now when I type that, it doesn't recognize the command.
How do I get back the ability to use the text editor and how did I lose it?
In a windows terminal, you can launch notepad++ with the following:
start notepad++ <filename>
Note that the filename is optional.
Most likely the directory in which the Notepad++ executable resides is not in your system's PATH. For information about fixing this please see How to set the path in Windows 2000 / Windows XP.
If you are using gitbash or cygwin, you can create an alias
alias np='start notepad++'
And use
np myfile.txt
This is what I have done, in this way you dont have to type notepad++
Create np.bat file with this set of commands
#echo off
start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" %*
place np.bat file in c:\Windows
open the command prompt and type np or np myfile.txt and enter.
One way is to make a change to this registry key:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Notepad++.exe]
You can download a zipped .reg file from Donn Felker that lets you open a file with just an n shortcut.
I edited the .reg before running it and to make sure the path to Notepad++ is correct (e.g. C:\Program Files (x86)) and I also changed the shortcut to n instead of n.
Then double click to add to your registry.