I want to make a launcher for a c program I made and I want it to run in terminal. How would I do this? I don't even have the slightest idea
Just create a text file, save it to the Desktop as e.g. my_C_program.command (note the .command suffix), then in the text file you can put whatever terminal commands you like, e.g.
# run my_C_program
my_C_program arg1 arg2
Note: after saving the .command file you need to make sure it is executable:
$ chmod +x ~/Desktop/my_C_program.command
This will give you a double-clickable icon on the desktop called my_C_program that runs my_C_program via the command line. (This assumes my_C_program is somewhere in your PATH).
Double-click your programm
You will asked for a programm to open your programm (sounds strage, I know)
Search for "Terminal" & Choose it
That's it! Now your programm should open when you double-click it.
Related
I have a problem that I just can't wrap my head around. I have a minimal example makefile that is supposed to compile a very simple .c file into an executable program.
When I run make, the compiler starts compiling and then produces an error message
"T:\printOffsets.c:10:21: error: bootIfc.h: No such file or
directory"
Then I copy the exact same command line make is using to build the target and run it directly in the same Windows command shell instance, and suddenly compilation succeeds without errors!! The command line is (path names simplified):
T:\perl\c\bin\gcc.exe T:\printOffsets.c -IT:\include\ -o
D:\printOffsets.exe
How do I know? Well, make prints the command line before it executes it, so I simply copy&paste from the shell.
I don't get it! How is this possible?? How can the exact same command work on the shell and fail if launched from within a Makefile??
I'm using GNU Make 3.82 on Windows 7, by the way.
When command in makefile is giving different result from shell, just make sure it is using the shell you want.
Add a phony target in your make file:
.PHONY:testshell
testshell:
echo $(SHELL)
And run:
gmake testshell
If the result is not your favorite shell you can force it by adding a line such as this one at the beginning of your makefile:
SHELL=C:\Windows\System32\cmd.exe
If you are not sure of full path of your shell, just open a DOS console and launch:
where cmd
Edit: alternative solution
When using sh shell instead of cmd shell, you can also replaces all backslashes in commands with slashes and keep using sh.
Edit 2: change shell for a single target
In Operating System concept i want to write a C program to make Unix command works as DOS commands.
It Means when ever i press Unix Command like ls -which is used for Display list of Files- it works like Dir command in DOS.Could you please help me out with this?
Starting with the ls command as example, take input from user for the command. If the command is ls call a windows function that will display the content of the current working directory(). For ls,
you need to get first the current working directory. GetCurrentDir() for windows will be your first step. This will help How do I get the directory that a program is running from?
Then you can list the files in directory like this https://msdn.microsoft.com/en-us/library/windows/desktop/aa365200(v=vs.85).aspx. But you do need the output of first step.
Other commands can also be implemented like this
I am using mac OS x and have written C program using GCC compiler.
But while running the program on terminal I am being shown that "No such file or directory found"
Please help me how to select the path?
run it with $./yourProgramFile command the ./ in the beginning is important. It means the program resides in the current directory.
Example:
/path/to/your/cFile $ gcc myfile.c -o myfile
/path/to/your/cFile $ ./myfile
You can do one of two things
1) Add the program's folder to the system's PATH; that way, you can call the program from any location. If it's a program you plan to use constantly, this is the best option.
Here's a way to do that:
Open up the .profile file in your home directory using any text editor.
Paste the following code anywhere in the file, preferably around the bottom of the file.
#make sure there's no space in the pasted code
export PATH=$PATH:path_to_the_program
Save it and restart your computer. That should put the program in the system's PATH.
2) Navigate to the folder of the program; then type
./program_name
Hope the explanation is clear and the answer helps.
Make sure that when you compile the program, you should use -o program_name to make the program name whatever you want it to be; otherwise, the program's name will be a.out, which would be very confusing.
I have a bunch of shell scripts that used to run on a Linux machine. Now, we've switched over to Windows, and I need to run these scripts there. I have Cygwin installed, but is there a way to make the script run using Cygwin, but the call is made from Windows batch?
Sure. On my (pretty vanilla) Cygwin setup, bash is in c:\cygwin\bin so I can run a bash script (say testit.sh) from a Windows batch file using a command like:
C:\cygwin\bin\bash testit.sh
... which can be included in a .bat file as easily as it can be typed at the command line, and with the same effect.
One more thing - if You edited the shell script in some Windows text editor, which produces the \r\n line-endings, cygwin's bash wouldn't accept those \r. Just run dos2unix testit.sh before executing the script:
C:\cygwin\bin\dos2unix testit.sh
C:\cygwin\bin\bash testit.sh
If you have access to the Notepad++ editor on Windows there is a feature that allows you to easily get around this problem:
Open the file that's giving the error in Notepad++.
Go under the "Edit" Menu and choose "EOL Conversion"
There is an option there for "UNIX/OSX Format." Choose that option.
Re-save the file.
I did this and it solved my problems.
Hope this helps!
Read more at http://danieladeniji.wordpress.com/2013/03/07/microsoft-windows-cygwin-error-r-command-not-found/
Just wanted to add that you can do this to apply dos2unix fix for all files under a directory, as it saved me heaps of time when we had to 'fix' a bunch of our scripts.
find . -type f -exec dos2unix.exe {} \;
I'd do it as a comment to Roman's answer, but I don't have access to commenting yet.
The existing answers all seem to run this script in a DOS console window.
This may be acceptable, but for example means that colour codes (changing text colour) don't work but instead get printed out as they are:
there is no item "[032mGroovy[0m"
I found this solution some time ago, so I'm not sure whether mintty.exe is a standard Cygwin utility or whether you have to run the setup program to get it, but I run like this:
D:\apps\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico bash.exe .\myShellScript.sh
... this causes the script to run in a Cygwin BASH console instead of a Windows DOS console.
If you don't mind always including .sh on the script file name, then you can keep the same script for Cygwin and Unix (Macbook).
To illustrate:
1. Always include .sh to your script file name, e.g., test1.sh
2. test1.sh looks like the following as an example:
#!/bin/bash
echo '$0 = ' $0
echo '$1 = ' $1
filepath=$1
3. On Windows with Cygwin, you type "test1.sh" to run
4. On a Unix, you also type "test1.sh" to run
Note: On Windows, you need to use the file explorer to do following once:
1. Open the file explorer
2. Right-click on a file with .sh extension, like test1.sh
3. Open with... -> Select sh.exe
After this, your Windows 10 remembers to execute all .sh files with sh.exe.
Note: Using this method, you do not need to prepend your script file name with bash to run
I have been writing my code in IDE,I just read that there also existed a Command Line Development Environment in which the code is written in DOS.I googled but found no results on how to use the command line development environment.My OS is Windows XP.I would be very thankful for your help me write the hello world program in DOS and also explain how to run it.
You simply use whatever text editor you like to create the C sourse file(s) then invoke the compiler command line(s) to compile and link the program (typically, an IDE is doing exactly that, but in a behind-the-scene manner). How the command line is invoked depends on the exact toolchain you're using.
You might also need to set up an environment for you particular compiler toolchain (the right paths and various other env variables might need set up).
For Visual C++ the environment might be set up using a batch file installed by Visual Studio:
vcvarsall x86
Invoking the compiler could be as simple as:
cl helloworld.c
or for C++ (for some reason it issues a non-fatal warning if you don't give it an option configuring details about how it should implement exceptions):
cl /EHsc helloworld.cpp
The particulars are very dependent on the compiler you're using - you should read the docs for that compiler.
Also, the options you use depend on your particular situation and needs. Scripts/batch files and/or makefile can help you manage the complexity of the options you might need to use.
DOS is not dead.... yet!
fahad
There are a number of methods by which you can enter code in DOS (see EDIT further on down).
(1) You can send keystrokes directly to a file
You do this by redirecting output to CON (the console) to a file. The only oddity of this method is that you end the 'session' by entering a CTRL-Z when you are finished.
It's basic, but this is how it goes.
Firstly, suppose you want to display "Hello World" on the screen, a simple batch file containing the following two lines is all that is required:
#echo off
echo Hello World
The '#echo off' is commonly found at the start of all batch files. It simply instructs the command interpretter NOT to display each command as it is being executed (or parsed).
One more thing before we start. Throughout this answer, I will assume your program is named 'helloworld.bat'.
Enter the following lines one after the other pressing the ENTER key at the end of each line:
copy con helloworld.bat
#echo off
echo Hello World
^Z
The '^Z' is displayed when you press the CTRL-Z key combination (don't forget to press the ENTER key as well).
When you press the ENTER key after CTRL-Z, DOS displays the familiar '1 File(s) copied' messege.
You can now execute the batch file program by simply entering the program's name like this:
helloworld
And DOS will display the following:
Hello World
It can't get any more basic than that.
(2) You can use DOS' EDIT program
This is a DOS based IDE retained from around the mid-90's. Simply enter the following command:
edit
And EDIT will open in the same DOS window. When you close EDIT, you are returned back to DOS again.
EDIT also works with your mouse.
Once EDIT opens, enter the following two lines of code:
#echo off
echo Hello World
Then, click on [File], [Save], type: 'helloworld.bat' in the "File Name" input field, use your mouse to change directories in the "Directories:" pane if you want to, then click [OK]. To return to DOS, click [File], [Exit].
EDIT version 4.5 (I think) was context-sensitive and displayed code using different colours to seperate key word, different data type, symbols etc.
(3) Use Windows' built-in Notepad
This is simple. At the command prompt, enter the following command:
notepad
And Notepad will fire up. It's a simple text editor and does the job when entering small programs.
(4) Use Notepad++. It's FREE!!
Notepad++ is the programmer's choice. It's free, full of useful features and customisable. Find it on the net by searching for "notepad++".
From your comment, "Just some knowledge so I can say that I know one way to do programming without IDE" I would say learn to write simple batch files. They can be run from Explorer but they exist as a holdover from the DOS days.
Start a command prompt window (Start->Run->'cmd'), this will open a window and show a prompt, most likely "c:\" or some other path.
Type the following command (followed by )
echo "Hello World"
You should see:
"Hello World"
c:\
Now, using whatever editor you'd like, create a text file with that command as the only line. Name the file "hello.bat". When you are at the command prompt you can execute the batch file like so:
c:\hello.bat
"Hello World"
c:\
You have now programmed using the DOS command line. For more commands and such, start with the help system.
c:\help
Which will display all the available commands for your batch file.
Microsoft has an online reference here.
DOS is dead for all practical purposes. Under Windows your options boil down to the following:
Use an IDE. Visual Studio is one example, Qt another. You can write programs for the commandline with an IDE.
Use a proper text editor, build tool and other helper tools. You might use gvim for editing code, make for building your project and git for version control. You might as well use the GNU coreutils for other helpers, or maybe even the entire cygwin package.
Bro, use gcc compiler for which write ur code in any text editor then compile ur code in windows shell or u can say command line environment.
Look!
Prompt:/> gcc source_file_name.c
This command compiles ur code,
If there is any error, u will get dispalyed with line numbers,
now, every program creates its exe file by the name a.exe by default.
To, get the output of ur program,
Prompt:/> a.exe
O/P
Hello World!
To change the name of the exe file there is also a command..