Sponsored Content
Top Forums Shell Programming and Scripting Redirecting stdin/stdout to/from command from/to string Post 302403683 by doc_cypher on Saturday 13th of March 2010 11:11:29 PM
Old 03-14-2010
Question Redirecting stdin/stdout to/from command from/to string

Hi,
I am working on a project where I have to generate and execute nasm code on-the-fly. I generate the code in a file program.asm and then execute it.This output is to stdout which i redirect to an output file which i read back to compare results:
system("nasm -f elf program.asm > output");
The problem is I have to do this process (generate code and execute) a lot of times each time i run my program which slows the execution time due to so much file I/O.

Is there some shell trick by which I can generate my code in a string buffer (instead of the file program.asm) and pass it as input to nasm.
Similarly, can I capture the output of nasm into another string buffer without writing it to a file.

Same applies for compiling c programs using gcc. Can my c program be present in a string which i then compile using gcc by redirecting its input from a file to the string. Likewise, can i redirect the output of my c program to a string instead of stdout or any other file before.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting to stdin

Hi, I'm having trouble with my script. I have to select different choices without any interaction from a menu that looks like : a - xxxxxxxxxxxxxx b - xxxxxxxxxxxxxx c - xxxxxxxxxxxxxx d - xxxxxxxxxxxxxx I tried things like : echo "a" >&0 read < echo "a" but none worked. Any... (4 Replies)
Discussion started by: flame_eagle
4 Replies

2. Programming

stdout/stdin + flushing buffers

Hi all I've run into a snag in a program of mine where part of what I entered in at the start of run-time, instead of the current value within printf() is being printed out. After failing with fflush() and setbuf(), I tried the following approach void BufferFlusher() { int in=0;... (9 Replies)
Discussion started by: JamesGoh
9 Replies

3. Shell Programming and Scripting

Redirecting stdin from fd 3-9?

Hi I'm trying to do something on the bash command line that I will later put into a bash shell script. I'm trying to take a program that reads stdin (using getline) and be able to keep it running in the background and fire "commands" to it. So what I thought I should do was to try taking... (3 Replies)
Discussion started by: niceguyeddie
3 Replies

4. UNIX for Dummies Questions & Answers

Redirect stdin stdout to multiple files

Hi, i know how to a) redirect stdout and stderr to one file, b) and write to two files concurrently with same output using tee command Now, i want to do both the above together. I have a script and it should write both stdout and stderr in one file and also write the same content to... (8 Replies)
Discussion started by: ysrini
8 Replies

5. Shell Programming and Scripting

can't close stdin/stdout in shell

#!/bin/sh exec 0</dev/null exec 1>/dev/null ls -l /proc/self/fd >&2 produces total 0 lr-x------ 1 tyler users 64 Feb 18 10:38 0 -> /proc/7886/fd lrwx------ 1 tyler users 64 Feb 18 10:38 1 -> /dev/pts/4 lrwx------ 1 tyler users 64 Feb 18 10:38 2 -> /dev/pts/4 I've verified the shell is... (10 Replies)
Discussion started by: Corona688
10 Replies

6. Shell Programming and Scripting

redirecting to stdout in betwen command

can anyone help me in making singleline command for Capital Letters are folders ,small letter are files X,Y,Z are subfolders of A as shown below A - X,Y,Z Folder X has three files a.txt,b.txt,c.txt similarly Y,Z. as shown below X- a.txt,b.txt,c.txt Y- a.txt,b.txt,c.txt Z-... (4 Replies)
Discussion started by: phoenix_nebula
4 Replies

7. Programming

read and write stdin/stdout in unix

Hi, i am using the below program to read from the standard input or to write to standard out put. i know that using highlevel functions this can be done better than what i have done here. i just want to know is there any other method by which i find the exact number of characters ( this... (3 Replies)
Discussion started by: MrUser
3 Replies

8. UNIX for Dummies Questions & Answers

STDIN and STDOUT

Hallo, i have a script like: if ;then echo "OK" else echo "ERROR $2 is missing" fi; if ;then touch $2 fi; if ;then cat $1 | grep xy > $2 (1 Reply)
Discussion started by: eightball
1 Replies

9. Shell Programming and Scripting

Redirecting stdion, stdout within an AT command

Hello, I'm strugling with some redirecting and all help is apreciated. The following program is working as expected, but the result of the AT command doesn't go to any file. Thanks in advance for the help. #!/bin/bash modem=/dev/ttyUSB1 file=/root/imsi.txt # print error to stderr and exit... (4 Replies)
Discussion started by: cleitao
4 Replies

10. Shell Programming and Scripting

[stdin / stdout] Strategies for redirecting outputs

Well.. let's say i need to write a pretty simple script. In my script i have 2 variables which can have value of 0 or 1. $VERBOSE $LOG I need to implement these cases: ($VERBOSE = 0 && $LOG = 0) => ONLY ERROR output (STDERR to console && STDOUT to /dev/null) ($VERBOSE = 1... (5 Replies)
Discussion started by: Marmz
5 Replies
NASM(1) 						      General Commands Manual							   NASM(1)

NAME
nasm - the Netwide Assembler, a portable 80x86 assembler SYNOPSIS
nasm [ -@ response file ] [ -f format ] [ -o outfile ] [ -l listfile ] [ options... ] filename nasm -h nasm -v DESCRIPTION
The nasm command assembles the file filename and directs output to the file outfile if specified. If outfile is not specified, nasm will derive a default output file name from the name of its input file, usually by appending `.o' or `.obj', or by removing all extensions for a raw binary file. Failing that, the output file name will be `nasm.out'. OPTIONS -@ filename Causes nasm to process options from filename as if they were included on the command line. -a Causes nasm to assemble the given input file without first applying the macro preprocessor. -D macro[=value] Pre-defines a single-line macro. -d macro[=value] Same as the -D option. -e Causes nasm to preprocess the given input file, and write the output to stdout (or the specified output file name), and not actually assemble anything. -f format Specifies the output file format. To see a list of valid output formats, use the -hf option. -g Causes nasm to generate debug information in selected format -h Causes nasm to exit immediately, after giving a summary of its invocation options. -hf Same as -h , but also lists all valid output formats. -I directory Adds a directory to the search path for include files. The directory specification must include the trailing slash, as it will be directly prepended to the name of the include file. -i directory Same as the -I option. -l listfile Causes an assembly listing to be directed to the given file, in which the original source is displayed on the right hand side (plus the source for included files and the expansions of multi-line macros) and the generated code is shown in hex on the left. -M Causes nasm to output Makefile-style dependencies to stdout; normal output is suppressed. -O number optimize branch offsets (-O0 disables, default). -o outfile Specifies a precise name for the output file, overriding nasm's default means of determining it. -P file Specifies a file to be pre-included, before the main source file starts to be processed. -p file Same as the -P option. -r Causes nasm to exit immediately, after displaying its version number. (obsolete) -s Causes nasm to send its error messages and/or help text to stdout instead of stderr. -t Causes nasm to assemble in SciTech TASM compatible mode -U macro Undefines a single-line macro. -u macro Same as the -U option. -v Causes nasm to exit immediately, after displaying its version number. -w[+-]foo Causes nasm to enable or disable certain classes of warning messages, for example -w+orphan-labels or -w-macro-params -X format specifies error reporting format (gnu or vc). -Z filename Causes nasm to redirect error messages to filename. This option exists to support operating systems on which stderr is not easily redirected. SYNTAX This man page does not fully describe the syntax of nasm's assembly language, but does give a summary of the differences from other assem- blers. Registers have no leading `%' sign, unlike gas, and floating-point stack registers are referred to as st0, st1, and so on. Floating-point instructions may use either the single-operand form or the double. A TO keyword is provided; thus, one could either write fadd st0,st1 fadd st1,st0 or one could use the alternative single-operand forms fadd st1 fadd to st1 Uninitialised storage is reserved using the RESB, RESW, RESD, RESQ, REST and RESO pseudo-opcodes, each taking one parameter which gives the number of bytes, words, doublewords, quadwords or ten-byte words to reserve. Repetition of data items is not done by the DUP keyword as seen in DOS assemblers, but by the use of the TIMES prefix, like this: message: times 3 db 'abc' times 64-$+message db 0 which defines the string `abcabcabc', followed by the right number of zero bytes to make the total length up to 64 bytes. Symbol references are always understood to be immediate (i.e. the address of the symbol), unless square brackets are used, in which case the contents of the memory location are used. Thus: mov ax,wordvar loads AX with the address of the variable `wordvar', whereas mov ax,[wordvar] mov ax,[wordvar+1] mov ax,[es:wordvar+bx] all refer to the contents of memory locations. The syntaxes mov ax,es:wordvar[bx] es mov ax,wordvar[1] are not legal at all, although the use of a segment register name as an instruction prefix is valid, and can be used with instructions such as LODSB which can't be overridden any other way. Constants may be expressed numerically in most formats: a trailing H, Q or B denotes hex, octal or binary respectively, and a leading `0x' or `$' denotes hex as well. Leading zeros are not treated specially at all. Character constants may be enclosed in single or double quotes; there is no escape character. The ordering is little-endian (reversed), so that the character constant 'abcd' denotes 0x64636261 and not 0x61626364. Local labels begin with a period, and their `locality' is granted by the assembler prepending the name of the previous non-local symbol. Thus declaring a label `.loop' after a label `label' has actually defined a symbol called `label.loop'. DIRECTIVES SECTION name or SEGMENT name causes nasm to direct all following code to the named section. Section names vary with output file format, although most formats support the names .text, .data and .bss. (The exception is the obj format, in which all segments are user-defin- able.) ABSOLUTE address causes nasm to position its notional assembly point at an absolute address: so no code or data may be generated, but you can use RESB, RESW and RESD to move the assembly point further on, and you can define labels. So this directive may be used to define data structures. When you have finished doing absolute assembly, you must issue another SECTION directive to return to normal assembly. BITS 16, BITS 32 or BITS 64 switches the default processor mode for which nasm is generating code: it is equivalent to USE16 or USE32 in DOS assemblers. EXTERN symbol and GLOBAL symbol import and export symbol definitions, respectively, from and to other modules. Note that the GLOBAL direc- tive must appear before the definition of the symbol it refers to. STRUC strucname and ENDSTRUC, when used to bracket a number of RESB, RESW or similar instructions, define a data structure. In addition to defining the offsets of the structure members, the construct also defines a symbol for the size of the structure, which is simply the structure name with _size tacked on to the end. FORMAT-SPECIFIC DIRECTIVES ORG address is used by the bin flat-form binary output format, and specifies the address at which the output code will eventually be loaded. GROUP grpname seg1 seg2... is used by the obj (Microsoft 16-bit) output format, and defines segment groups. This format also uses UPPER- CASE, which directs that all segment, group and symbol names output to the object file should be in uppercase. Note that the actual assem- bly is still case sensitive. LIBRARY libname is used by the rdf output format, and causes a dependency record to be written to the output file which indicates that the program requires a certain library in order to run. MACRO PREPROCESSOR Single-line macros are defined using the %define or %idefine commands, in a similar fashion to the C preprocessor. They can be overloaded with respect to number of parameters, although defining a macro with no parameters prevents the definition of any macro with the same name taking parameters, and vice versa. %define defines macros whose names match case-sensitively, whereas %idefine defines case-insensitive macros. Multi-line macros are defined using %macro and %imacro (the distinction is the same as that between %define and %idefine), whose syntax is as follows: %macro name minprm[-maxprm][+][.nolist] [defaults] <some lines of macro expansion text> %endmacro Again, these macros may be overloaded. The trailing plus sign indicates that any parameters after the last one get subsumed, with their separating commas, into the last parameter. The defaults part can be used to specify defaults for unspecified macro parameters after min- param. %endm is a valid synonym for %endmacro. To refer to the macro parameters within a macro expansion, you use %1, %2 and so on. You can also enforce that a macro parameter should contain a condition code by using %+1, and you can invert the condition code by using %-1. You can also define a label specific to a macro invocation by prefixing it with a double % sign. Files can be included using the %include directive, which works like C. The preprocessor has a `context stack', which may be used by one macro to store information that a later one will retrieve. You can push a context on the stack using %push, remove one using %pop, and change the name of the top context (without disturbing any associated defini- tions) using %repl. Labels and %define macros specific to the top context may be defined by prefixing their names with %$, and things spe- cific to the next context down with %$$, and so on. Conditional assembly is done by means of %ifdef, %ifndef, %else and %endif as in C. (Except that %ifdef can accept several putative macro names, and will evaluate TRUE if any of them is defined.) In addition, the directives %ifctx and %ifnctx can be used to condition on the name of the top context on the context stack. The obvious set of `else-if' directives, %elifdef, %elifndef, %elifctx and %elifnctx are also supported. BUGS
Please report bugs through the bug tracker function at http://nasm.sourceforge.org. SEE ALSO
as(1), ld(1). The Netwide Assembler Project NASM(1)
All times are GMT -4. The time now is 12:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy