Thread: Shell commands

  1. #1
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    127

    Shell commands

    Hi,

    I have a shell file with this content:

    Code:
    clear
    
    
    gcc -g -Wall -Wextra -pedantic -std=c11 try40.c -lm -o try40.out
    
    
    ./try40.out
    How can I execute ./try40.out only in case gcc issues no warning or error ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,334
    Look at $?

    Code:
    gcc -g -Wall -Wextra -pedantic -std=c11 try40.c -lm -o try40.out
    if [ $? -eq 0 ]; then ./try40.out ; fi
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    127
    Quote Originally Posted by Salem View Post
    Look at $?

    Code:
    gcc -g -Wall -Wextra -pedantic -std=c11 try40.c -lm -o try40.out
    if [ $? -eq 0 ]; then ./try40.out ; fi
    Thanks this works in case of error. In case of only warning(s) , try40.out is executed anyway. Maybe turn warnings into errors ? Other solution ?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,334
    -Werror is one way

    Redirecting the stderr of the compilation to a file, and checking whether that file is empty is another.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 01:56 AM
  2. Shell Commands
    By Frantic- in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2005, 11:35 AM
  3. Program to execute shell commands.
    By LiquidLithium in forum C++ Programming
    Replies: 6
    Last Post: 09-01-2004, 12:22 PM
  4. Sending Shell Commands
    By Pudnut in forum C# Programming
    Replies: 2
    Last Post: 08-29-2004, 01:13 AM
  5. Executing shell/dos commands
    By Zaarin in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2001, 10:29 PM

Tags for this Thread