LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2011, 10:07 PM   #1
cryingthug
Member
 
Registered: Jun 2009
Posts: 131

Rep: Reputation: 18
Running a C program?


Hi I have written two C programs that look almost the same. One will run but the other will not run by itself.

This is how I run them:

Code:
$  ex1
This is a C program.
And here is the other:

Code:
$ ex2
bash: /home/james/bin/ex2: cannot execute binary file
Here is ex1:

Code:
// This is a comment.
#include <stdio.h>

int main()
{
    puts("This is a C program\n");
    return 0;
}
Here is ex2:

Code:
#include <stdio.h>

int main()
{
    puts("This is another program\n");
    return 0;
}

Last edited by cryingthug; 10-19-2011 at 10:09 PM. Reason: error
 
Old 10-19-2011, 10:40 PM   #2
Ian John Locke II
Member
 
Registered: Mar 2008
Location: /dev/null
Distribution: Slackware, Android, Slackware64
Posts: 130

Rep: Reputation: 17
Did you compile ex2 on that machine or were the binaries compiled elsewhere? That's the only thing I can think of honestly, unless there's a homoglyph in the second file that somehow compiled.
 
1 members found this post helpful.
Old 10-19-2011, 11:12 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Try these:

Code:
ls -l ex1; file ex1; which ex1; ./ex1
ls -l ex2; file ex2; which ex2; ./ex2
 
1 members found this post helpful.
Old 10-20-2011, 08:43 AM   #4
Ian John Locke II
Member
 
Registered: Mar 2008
Location: /dev/null
Distribution: Slackware, Android, Slackware64
Posts: 130

Rep: Reputation: 17
Quote:
Originally Posted by NevemTeve View Post
Try these:

Code:
ls -l ex1; file ex1; which ex1; ./ex1
ls -l ex2; file ex2; which ex2; ./ex2
I have to believe that if ex1 ran without incident and that it's recognizing ex2 as a binary that the ./ is not required since PATH probably contains '.'.
file ex[12] should provide some good details though. (I'd forgotten about the information it provides since I encounter this problem almost never.)
 
Old 06-20-2012, 06:14 AM   #5
cryingthug
Member
 
Registered: Jun 2009
Posts: 131

Original Poster
Rep: Reputation: 18
Thanks for your help. I compiled the programs differently. That is what caused the problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
running a program from within QT kooshball Programming 4 06-14-2005 05:08 PM
Running a program rj686 Linux - Software 16 10-10-2004 07:19 PM
Running a new program bananaman Linux - Newbie 4 04-08-2003 04:00 PM
Running a C program isaacais Linux - Newbie 3 12-11-2002 02:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration