473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

execute command line arguments

please let me know

if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.t xt,pt2.txt,pt3. txt) to
prog.c through command prompt if i am working on linux

please reply urgently
Feb 24 '08 #1
4 2989

<ne**********@y ahoo.co.inwrote in message
news:6a******** *************** ***********@e25 g2000prg.google groups.com...
please let me know

if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.t xt,pt2.txt,pt3. txt) to
prog.c through command prompt if i am working on linux

please reply urgently
typer

int main(int argc, char **argv)

argc is the number arguments the user typed onm the commandline. Argv is an
array of those arguments, this is to say argv[0] is the name of the program.
argv[1] the first argument, argv[2] the second, and so forth.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Feb 24 '08 #2
ne**********@ya hoo.co.in wrote:
please let me know

if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.t xt,pt2.txt,pt3. txt) to
prog.c through command prompt if i am working on linux

please reply urgently
We are not your contract workers. We try to help but we cannot help you
with your last minute problems.

If your program executable is named 'prog', to give it the arguments
pt1.txt, pt2.txt and pt3.txt do at the command prompt and with the
programs's directory as your working directory:

prog pt1.txt pt2.txt pt3.txt

The general formula is:

PROGRAME [ARG 1] [ARG 2] [...]

You first type the program's name, as you would for any other program
and then type out it's arguments one after the other, separated by a
space. This will do fine for starting out. Later on you might like to
write a general purpose arguments processor along the lines of getopt
and others that handle more complicated formats and conditions.

PS. Note that in the example above argc will be four, not three, as the
program's invocation name also counts as a parameter, a difference from
languages like Java.

Feb 24 '08 #3
ne**********@ya hoo.co.in wrote:
>
say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.t xt,pt2.txt,pt3. txt) to
prog.c through command prompt if i am working on linux
This is a questoin about how to use the linux shell. You should ask in a
linux group.
However you can probably find out the answer very much quicker by
examining any of the hundreds of shell scripts that will be on your
linux box. Many of them will invoke programmes such as sed, grep, awk
and so on with arguments.
Feb 24 '08 #4
On Feb 24, 5:36 pm, neha_chha...@ya hoo.co.in wrote:
if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.t xt,pt2.txt,pt3. txt) to
prog.c through command prompt if i am working on linux

prog.c is an odd name for an executable, but if that's
really what you have, you probably want to execute:

$ ./prog.c pt1.txt pt2.txt pt3.txt

This gives you argc == 4, argv[0] == "./prog.c",
and argv[i] == "pt$i.txt" for i in [1,2,3].

If you really want argc == 3, you could try:

$ ln -s prog.c pt1.txt && PATH=$PATH:. pt1.txt pt2.txt pt3.txt

or something like that.
Feb 24 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2072
by: tom | last post by:
Problem: In PHP, need to execute a program in (freebsd terms) /usr/local/bin in meta-terms: int i; i = (arguments); There seems to be quite a few execution methods in PHP (sorry in advance for being thick), and, er, I was wondering if someone could give me a quick pointer to appropriate ones I should study to:
4
9896
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " & pPrinterName & " """
4
7877
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service applications in a training class last week. The applications worked in the class, but when I tried to run them again over the weekend, they both bombed. Instead of getting my Web page, or the Web Service page, I get a page full of error text...
6
6008
by: PAPutzback | last post by:
The process and execute methods want a path to the executable otherwise they kick out a file not found. So how can I execute the following. It works fine from a command window. echo password| gpg.exe --yes --output c:\working\inbound\test.txt --passphrase 0 -d c:\working\inbound\anstest.gpg
1
7900
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument. I have to do it this way as the consumer of the service should not be able to change the argument - except by uninstalling and reinstalling the service. I created the service and the service itself works great. However, when I try to install...
0
2282
by: Elroyskimms | last post by:
I need to execute a batch file via ASP.Net. In my VB.Net code, I'm using System.Diagnostics.Process to call the batch file and its appropriate command line arguments. I'm using System.Diagnostics.Process.StandardError and System.Diagnostics.Process.StandardOutput to capture and view the output and error messages. My web.config file has the following: <identity impersonate="true" userName="administrator" password="password" />
1
9506
by: stikhs | last post by:
Hi! I want to execute a command line application through my programme!Is there any instruction that could help me do this?I want to give the arguments via the GUI that I build,so is it possible that i could pass the arguments of the command line programme through my source code? Thanks in advance!
3
6492
by: =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?= | last post by:
I have a .NET VC++ program, I want to execute some dos command from the program, e.g. copy some file, and etc. How do I do that?
7
9370
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should display the Windows form. The form is being displayed but the command only returns when the form is closed. I want the command line to return immediately, leaving the form displayed.
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.