System("read") command

Hello. I've got the following code in a program:
printf("%s", "the text that I want to print to the console");
system("read");
The purpose here is to have the text from the printf( ) statement above print to the console, and then have the program pause and wait for the user to hit any key (note that scanf( ) or other input functions are not appropriate here for two reasons: first, the keys the user hits actually appear on the console, and I don't want them to, and second, the user can type many, many keys and the program will not continue until he or she hits Enter -- I want the program to simply pause until any key is hit). I knew that with C++ on Windows I used to be able to achieve this perfectly using system("Pause"), but I found that this did not work with C on the Mac. Thanks to help from RayNewb and Cohi in a previous thread, they explained that system( ) was a stdlib.h function that could easily be used in C, and that I just needed to find the Unix-equivalent of the "Pause" command (which was a DOS command, which is why it wasn't working on the Mac). Ray and Cohi came up with the following statement to replace the DOS-oriented system("Pause"):
system( "read -n 1 -s -p "Press any key to continue..."; echo" );
As you can see from the code at the very top of the post, I ended up shortening this statement to simply system("read") because I found that, for my purposes at least, it did the exact same thing as the longer version shown directly above. In either case, they were right about this command, and this statement did exactly what I wanted it to, except for one problem...
Gievn the two statements at the top of the post, the expected result would be for the text from the printf( ) statement to print to the console, followed by a pause in the program waiting for a key to be hit, at which point the program would continue. This is exactly what happens, only backwards. The program starts off with a pause, waiting for any key to be hit, and when a key is hit, only then does the printf( ) statement run and the text appear on the console. This happens whether I use the short version of the "read" statement or the full version that Ray and Cohi came up with. Can anyone help explain this? Any help is greatly appreciated.

Tron55555 wrote:
I know the fprintf() function, but I thought it was only used to write to files
Important plot point - everything is a file.
What is it that allows "stdout" to be used in place of a file name in this function's argument? Since "stdout" is a pointer like you said, does that mean that any pointer could be used for the first argument in the fprintf() function, not just file pointers? How's that work?
fprintf doesn't take a file name. It takes a "FILE *". You can create one of those with "fopen()" or you can use the pre-defined ones for standard input, output, and error. You can use any valid "FILE *" for the argument.
Do you guys have any recommendation of which would be better (whether it would be better to use fflush(stdout) or fprintf(stderr, "") )? Is one of these solutions more appropriate than the other, or are they both the same in effect?
Neither. Don't write command-line tools that depend on the terminal. fflush(stdout) is more tedious to use in the code, but more robust. Otherwise, you would have some of your output going to stdout and some of it going to stderr, which becomes a hassle. But it is only a hassle when you are dealing with command-line tools that are using the command line as an interface, and those things are always a hassle. It is better to stick to stdout and then you can more easily pipe the output of one program to the input of another. If you are going to break that functionality, you might as well write a real GUI. If you do your command-line tool correctly, you can easily write a GUI wrapper for it and have both GUI and good command-ilne functionality.
I don't really know anything about this stuff, but you mentioned that it's generally a bad idea to write command-line apps that have dependencies on the Terminal. Do you know of any other way to achieve the type of pause I'm trying to achieve without using the Terminal?
No. If you want to have a user interface, you have to interact. Unix was designed around the idea of a toolbox of simple programs that can be combined (piped) together to do clever things. You shouldn't have a requirement for terminal interaction. The basic functionality should be entirely driven by the command line so your tool could be easily used by other tools. If you really want an interface, add one, but require a "-i" flag to trigger interactive mode or maybe use "isatty()" to find out automatically (The "i" flag would be more robust though).
Consider the shell itself. It is, by definition, an interactive program. Right? Wrong. It can be run non-interactively too. In fact, non-interactive behavior is the default.
I've heard of them before, but don't know anything about them. If anyone has spare time, could you give me an explanation of what they do (doesn't have to be anything in detail -- just tyring to get some really basic idea of what they are, and what all the fuss over them is about). Thanks for your reply, eric.
It is an easy to use library for (fully) interacting with the terminal. It was a bigger deal before everyone had graphical user interfaces. There are umpteen different kinds of terminals and configurations and curses knows them all. You can even do text windows. Still, it is "easier" than interacting with the terminal, but only because the terminal is so cryptic.
Tron55555 wrote:
P.S. -- on a separate note, can anyone tell me, when formatting a quote on these forums, how I can write who's quote is it? When the quote says, for example, "etresoft wrote..." -- how do I do that? I checked the Help section under How to Format Text, but it didn't have anything about quotes. Thanks.
etresoft wrote:
Just hit the "quotes" button and see how the forum does it.
"Abraham Lincoln" wrote:
Four score and seven years ago...

Similar Messages

  • How to Run the NEW "System Info Command" in Tiger ?????

    I am new to Applescript and was wondering if someone could help me on how to run the new "System Info Command"?
    Thanks!!!

    The "system info" command that red_menace uses above is the new system info command that's mentioned on the web page you referenced. However, red's example only displays the "long user name" and the "AppleScript version" in the dialog.
    The entire system info record actually contains all of these items, each of which you can access just like red_menace shows you in his example:
    AppleScript version
    AppleScript Studio version
    system version
    short user name
    long user name
    user ID
    user locale
    home directory
    boot volume
    computer name
    host name
    IPv4 address
    primary Ethernet address
    CPU type
    CPU speed
    physical memory
    Steve
    PS - if you switch Script Editor over so the bottom pane displays the "Event Log" you'll see the entire system info record displayed in the log when you run red_menace's script.

  • Tell ma abt read command with eg.

    abt read command in abap

    hi
    good
    To read a single line of any table, use the statement:
    READ TABLE <itab> <key> <result>.
    For the statement to be valid for any kind of table, you must specify the entry using the key and not the index. You specify the key in the <key> part of the statement. The <result> part can specify a further processing option for the line that is retrieved.
    If the system finds an entry, it sets SY-SUBRC to zero, if not, it takes the value 4, as long as it is not influenced by one of the possible additions. If the internal table is an index table, SY-TABIX is set to the index of the line retrieved. If the table has a non-unique key and there are duplicate entries, the first entry is read.
    Using the Table Key
    To use the table key of <itab> as a search key, enter <key> as follows:
    READ TABLE <itab> FROM <wa> <result>.
    or as follows
    READ TABLE <itab> WITH TABLE KEY <k1> = <f 1> ... <k n> = <f n> <result>.
    In the first case, <wa> must be a work area compatible with the line type of <itab>. The values of the key fields are taken from the corresponding components of the work area.
    In the second case, you have to supply the values of each key field explicitly. If you do not know the name of one of the key fields until runtime, you can specify it as the content of a field <n i > using the form (<n i >) = <f i >. If the data types of <f i > are not compatible with the key fields, the system converts them.
    The system searches for the relevant lines as follows:
    Standard tables
    Linear search, where the runtime is in linear relation to the number of table entries.
    Sorted tables
    Binary search, where the runtime is in logarithmic relation to the number of table entries.
    Hashed tables
    The entry is found using the hash algorithm of the internal table. The runtime is independent of the number of table entries.
    Using a Different Search Key
    To use a key other than the table key as a search key, enter <key> as follows:
    READ TABLE <itab> WITH KEY = <f> <result>.
    or as follows
    READ TABLE <itab> WITH KEY <k1> = <f1> ... <k n> = <f n> <result>.
    In the first case, the whole line of the internal table is used as the search key. The contents of the entire table line are compared with the contents of field <f>. If <f> is not compatible with the line type of the table, the value is converted into the line type. The search key allows you to find entries in internal tables that do not have a structured line type, that is, where the line is a single field or an internal table type.
    In the second case, the search key can consist of any of the table fields <k 1 >...<k n >. If you do not know the name of one of the components until runtime, you can specify it as the content of a field <n i > using the form (<n i >) = <f i >. If <n i > is empty when the statement is executed, the search field is ignored. If the data types of <f i > are not compatible with the components in the internal table, the system converts them. You can restrict the search to partial fields by specifying offset and length.
    The search is linear for all table types. The runtime is in linear relation to the number of table lines.
    Specifying the Extra Processing Option
    You can specify an option that specifies what the system does with the table entry that it finds.
    Using a Work Area
    You can write the table entry read from the table into a work area by specifying <result> as follows:
    READ TABLE <itab> <key> INTO <wa> [COMPARING <f1> <f 2> ...
                                                 |ALL FIELDS]
                                      [TRANSPORTING <f1> <f 2> ...
                                                     |ALL FIELDS
                                                    |NO FIELDS].
    If you do not use the additions COMPARING or TRANSPORTING, the contents of the table line must be convertible into the data type of the work area <wa>. If you specify COMPARING or TRANSPORTING, the line type and work area must be compatible. You should always use a work area that is compatible with the line type of the relevant internal table.
    If you use the COMPARING addition, the specified table fields <f i > of the structured line type are compared with the corresponding fields of the work area before being transported. If you use the ALL FIELDS option, the system compares all components. If the system finds an entry with the specified key <key> and if the contents of the compared fields are the same, SY-SUBRC is set to 0. If the contents of the compared fields are not the same, it returns the value 2. If the system cannot find an entry, SY-SUBRC is set to 4. If the system finds an entry, it copies it into the target work area regardless of the result of the comparison.
    If you use the TRANSPORTING addition, you can specify the table fields of the structured line type that you want to transport into the work area. If you specify ALL FIELDS without TRANSPORTING, the contents of all of the fields are transported. If you specify NO FIELDS, no fields are transported. In the latter case, the READ statement only fills the system fields SY-SUBRC and SY-TABIX. Specifying the work area <wa> with TRANSPORTING NO FIELDS is unnecessary, and should be omitted.
    In both additions, you can specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
    Using a Field Symbol
    You can assign the table entry read from the table to a field symbol by specifying <result> as follows:
    READ TABLE <itab> <key> ASSIGNING <FS>.
    After the READ statement, the field symbol points to the table line. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.
    For further information about assigning table lines to field symbols, refer to Access Using Field Symbols.
    Examples
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
    DO 4 TIMES.
      LINE-COL1 = SY-INDEX.
      LINE-COL2 = SY-INDEX ** 2.
    INSERT LINE INTO TABLE ITAB.
    ENDDO.
    LINE-COL1 = 2. LINE-COL2 = 3.
    READ TABLE ITAB FROM LINE INTO LINE COMPARING COL2.
    WRITE: 'SY-SUBRC =', SY-SUBRC.
    SKIP.
    WRITE: / LINE-COL1, LINE-COL2.
    http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
    thanks
    mrutyun^

  • CALL 'SYSTEM' ID 'COMMAND'  cannot be used

    Hello,
    We were just told that with the latest kernal we are going to apply, we can no longer use the following command:
    CALL 'SYSTEM' ID 'COMMAND' FIELD CMD(250)
    We are thinking of using this function to replace it:
    CALL FUNCTION 'SXPG_CALL_SYSTEM'
    Does anyone have any other suggestions on other options we might have?
    Thanks!

    Bill,
    We are using function module SXPG_CALL_SYSTEM in our 4.7 system and it works fine.

  • Questionable System Events commands

    Are *key down* (key name) and *key up* (key name) legitimate "System Events" commands? I'm probably blind, but I don't find them in the System Events dictionary -- and yet they work, with dangers.
    For example:
    tell application "System Events"
    key down command
    display dialog "Computer will act as if command key is
    depressed until dialog is dismissed. (Dialog acts as
    a script delay until dismissed.)"
    key up command
    end tell
    But if anything prevents the script from reaching *key up command*, the only way I've
    found to escape the "key down" mode (and a great deal of weirdness) is a restart. (This
    may be reason enough to omit the commands from the dictionary.)
    Is there any other escape approach? Are there other dangers with these commands?
    Otherwise, I find them useful.

    More:
    The script I posted initially works as described on PPC version of 10.4.11, Intel Version of 10.4.11, 5.1.8, and 6.1.2 -- I've verified all of those.
    No freezes occur, but there are all kinds of things that don''t work if the command key is depressed. If the script fails to execute to the "key up command" command (say, due to an error), then the key remains "depressed," and all this weird behavior persists. I've tried everything I can think of to escape, but nothing has yet worked -- including force quitting anything. But restarting does undo the situation.
    (One escape approach I haven't yet tried is this: beginning after any "key down command" command and up to the "key up command" command, enclose everything in a try block and specify on error to "key up command." That might work, we'll see.)
    As to usefulness, the first thing I used it for was to make it easier for a user to make multiple selections in an open window -- no need to hold the command button down while clicking on items. I'm confident that it will be useful in a number of situations.

  • Why did we really need this "spanning-tree extend system-id" command?

    Folks,
    On the Spanning tree protocol I understood how does this spanning-tree extend system-id command work.
    But I have not understood why it is in place? or why do we really need it?
    Regards,
    Nikhil Kulkarni.

    Hi Nikhil,
    The STP and RSTP standard specifications mandate that each switch running STP/RSTP must have a unique Bridge ID (BID). Because Cisco runs STP or RSTP in each VLAN separately (called PVST and RPVST or PVRST), in each VLAN, the switch behaves like a standalone (albeit virtual) switch and thus, each STP/RSTP instance is required to have a unique BID to comply with the standard. Simply, having X VLANs means having X separate STP/RSTP instances and X unique BIDs.
    The question now is how to make sure the BIDs of STP/RSTP instances run on the same switch in different VLANs are truly unique. Older switches actually had a large reserve of MAC addresses. As new VLANs were created, these switches allocated a new MAC address for each new STP/RSTP instance in a new VLAN (recall that the BID originally consisted of the priority and the MAC address), making the BIDs unique.
    However, the consumption of MAC addresses this way was simply too large and ineffective. At the same time, having 65536 different values for priority in the BID was largely useless. So IEEE came with the idea of Extended System ID in which they reused a part of the priority field for a unique instance identifier. In Cisco's implementation, this field is populated with the VLAN number the STP/RSTP instance runs in. This easily and effectively makes the BID unique - even with the same priority for all VLANs on a single switch, and a single switch MAC address, multiple STP/RSTP instances running on this same switch with the same priority have different BIDs thanks to different VLAN numbers embedded into the BID.
    Some switch platforms actually allowed you to deactivate the Extended System ID and revert to the older style of assigning unique MAC addresses to individual STP/RSTP instance BIDs. That is why the command spanning-tree extend system-id exists in the first place. However, removing this command is only possible on those switching platforms which are equipped with 1024 MAC addresses for their disposal. Most new switching platforms have only 64 MAC addresses for their internal use, and while the spanning-tree extend system-id command is present in their configuration, you can not remove it. It is simply there to inform you that the Extended System ID is being used but you can not really deactivate it.
    Read more here:
    http://www.cisco.com/en/US/docs/switches/lan/catalyst6500/ios/12.2SXF/native/configuration/guide/spantree.html#wp1096536
    Best regards,
    Peter

  • How SAP BW system read cube data?? - Important

    Hi BW and database level gurus
    I have very simple question . I want to know how SAP BW system read data from the cube.
    If I write a simple BEx query and execute - how does system gets data from cube?
    Here is what I wish to know -
    1) Does it use SELECT statement after all to get data based on set of SID or DIM ids?
    2) What is the backend data retrieval architecture look like . Can someone provide me some digram to explain ?
    3) Data in cube is stored in ROLAP concept so then will I get same performance if I had simple transparent table? why should we use CUBE then?
    4) What are the steps that happens in backend ABAP that get us the expected result?
    Thanks and I will appreciate your reply
    AG
    Edited by: AM on Apr 10, 2008 2:48 AM

    Hi,
    Yes, it uses select statements to fetch data. It initially makes selection from the dimension tables for the necessary characteristics and then gets the corresponding key figures from the fact table.
    say for example, to fetch the top sales vales and customers from a region say India. Then, the select statement will make all customers from customer dimension belongining to the region India from the region dimension and finally gets the corresponding values from the fact table.
    If you use simple table, OLAP concept cannot be applied, and the way the master data is retirved for the corresponding transaction data is far more efficient in olap.
    Thanks

  • "System Exec" command in NT / W95 How to use?

    Hi LVers,
    I can start the shell with the System Exec command with LV, but how can I put
    additional (batch) commandos into it?
    I already tried:
    - piping "cmd < dir"
    - batch files "mybatch.bat"
    Where are the differencies btw. NT and W95
    thanks
    tom

    I am not sure that I understand what you are trying to do.
    Anyway, in LVWUtil32.zip you can find some VIs that improve the use of System Exec[http://digital.ni.com/public.nsf/3efedde4322f​ef19862567740067f3cc/824b3db43031317686256aaf00713​218/$FILE/LVWUtil32.zip]. As far as I remember you have some good documentation inside.
    Also, you can use a KeyGenerator [http://hamiltondesign-consulting.com/ftpfiles/Sen​dKey.zip] to send commands to a shell window (via keystrokes).
    Hope this helps

  • HIde Menu,System and Command Promt from transaction ivew

    Hi,
    Our client has implemented SAP HR module, year back.
    Now they are implementing ESS and they have done some developments for CLAIMS in R/3 earlier. Now they want to see those claims in portal. For that we have created transactional iview. Its coming fine in portal. But the only problem is that, its displaying sap standard menu. i.e menu, system and command promt in portal. Now my concern is how to hide these things ???
    Useful Answer's will rewarded.

    Put these parameters
    ~noHeaderOkCode = 1
    ~webTransactionType = EWT.
    in transaction sicf
    ->sap->bc->gui->sap->its-> Webgui
    push button gui configuration and set the parameters
    check with se93 if transaction is web enabled
    regards

  • How system read transaction for movement type

    Dear friends,
    We are facing problem - in case of movement type 101 system is reading PRD transcation key for valaue of inventory with another transaction key WRX.  I dont know the logic how system read transction key.
    If I use 101 movemment type then how system reads transcation key ie. GBB, PRD etc..... I need to know that logic . Please let me know and give me transction code to same I can check for other movement types.
    Thanks
    ravi

    Tcode OBYC is where all these transactions keys and all the G/ls are assigned to them.
    There are normal accounting entries at time of GR i.e.
    Material - Debit
    GR/IR - Credit
    AT  IR:
    Vendor - Credit
    GR/IR - Debit
    Now on above entries, system looks for transaction key for material and post its entry and then key for Gr/IR and posts the credit
    entry in case of GR and vice versa for IR.
    Please check these answered links for further details:
    obyc
    OBYC
    OBYC
    OBYC transaction?
    Edited by: Afshad Irani on Apr 20, 2010 4:04 PM
    Edited by: Afshad Irani on Apr 20, 2010 4:05 PM

  • Card is in the GlobalPlatform card life cycle OP_READY ,the READ command?

    I have alreay finshed the pre-personalization procedure,but I do the READ command:
    /send C0B0036EFF
    => C0 B0 03 6E FF ...n.
    (35167 usec)
    <= 6E 00 n.
    Status: CLA value not supported
    what error?
    And what can I do?
    I learn the card at the first time

    What READ command are you trying to execute? Is this something you expect the card manager to respond to or a specific applet on the card? Can you provide the full APDU trace of the session?
    Shane

  • Unwanted record is coming even after filtering through read command

    Hi All,
    I am fetching vbeln matnr fkimg brewand netwar from vbrp and kdmat erdat from lips. i am reading data as:-
    READ TABLE IT_lips WITH KEY VBELN = WA_VBRP-VGBEL MATNR = WA_VBRP-MATNR INTO WA_lips BINARY SEARCH.
    In this case data should filter according to read command ,but 1 record which exist with vbeln and matnr in vbrp and no corresponding record is there in lips is also coming in my final output.
    This is happening when i am giving a particular customer code in my selection screen.
    Is anyone have idea about this problem.
    Thanks ansd Regards,
    Ranu

    >
    ranu sharma wrote:
    >
    >
    >     CLEAR: wa_vbrK, WA_LIKN, WA_MALI, WA_VBPA,WA_LFA1,
    > WA_J_1IEXCHDR .
    >
    > .......
    > ........
    >
    > READ TABLE IT_MALI WITH KEY VBELN  = WA_VBRP-VGBEL MATNR = WA_VBRP-MATNR INTO WA_MALI BINARY SEARCH.
    >
    >       IF SY-SUBRC = 0.
    >
    >   IF WA_MALI-VBELN = WA_VBRP-VGBEL AND WA_MALI-MATNR = WA_VBRP-MATNR.
    >         WA_FINAL-MATNR = WA_MALI-MATNR.
    >          WA_FINAL-MATKL = WA_MALI-MATKL.
    >         WA_FINAL-ERDAT1 = WA_MALI-ERDAT.
    >         WA_FINAL-MTART = WA_MALI-MTART.
    >         WA_FINAL-TEXT_LIPS_MAKTX = WA_MALI-MAKTX.
    >         WA_FINAL-KDMAT = WA_MALI-KDMAT.
    >    ENDIF.
    >
    >   ENDIF.
    > ....
    > ....
    > enloop
    Hi Ranu,
    As I said in my earliar Post...
    You must be forgetting to clear the work area after appending or modifying ...
    Please clear  WA_FINAL  after it's processing is over for each record inside LOOP AT IT_VBRP INTO WA_VBRP...
    Hope it will solve your problem..
    Thanks & Regards
    ilesh 24x7
    ilesh Nandaniya

  • Wmii: plan9 installed, but no 'read' command

    I get the xmessage window from wmii-3.6 saying I have a plan9 installation, but there is no 'read' command.
    I searched for an answer, but I couldn't find anything.  Does anybody here have the same problem, or know
    how to fix it?

    You need to have /usr/local/plan9/bin or equivalent in your PATH.

  • Comedi read command and acquire waveforms VIs

    I am wondering about the implementation of the comedi read command in the VIs I got from the NI site.
    One of the VIs is called "acquire waveforms" which calls "comedi read". everything seems to be working fine, but I am very curious about a small part of the comedi read VI.
    If you look closely at it, you will see that after reading in the samples using the CIN that just calls read() , there is a formula node that basically asks the VI to save only the first half of the array. I am wondering why this would be so? Does it have to do with the way read() works?
    I tried changing the VI so that the all bytes from the read() call are entered into the "data" array. But when I do this, labview gets stuck.
    any ideas?

    Hello:
    This question belongs in the Measurement Hardware Driver Delvelopment Kit (DDK) Forum located here:
    http://exchange.ni.com/servlet/ProcessRequest?RHIV​EID=101&RPAGEID=8&RFORMNUMBER=3&RHIDETAG=TRUE&UCAT​EGORY_0=_321&UCATEGORY_S=0
    The Comedi driver set is supported by www.comedi.org but you might get some answers from the DDK Forum as well.
    Sincerely,
    Brooks B
    Applications Engineer

  • CALL 'SYSTEM' ID 'COMMAND'

    hi:
    constants:comm(90) value 'sh /usr/rvs/export/TNT2K7F/script/FRC12K7F.sh'.
      call 'SYSTEM' id 'COMMAND' field comm.
    can you tell me the  role of the sentence ,ths
    regards
    sophia

    Hi,
    'sh /usr/rvs/export/TNT2K7F/script/FRC12K7F.sh' is a unix command to run a unix script, and normally you would have to log on to the operating system to run this.
    call 'SYSTEM' id 'COMMAND' field comm calls this command from ABAP, meaning your SAP user can run a report which also runs the unix script.
    Regards,
    Nick

Maybe you are looking for

  • Daily User Stats of users log on for the Day

    Im need stats of users log on for the previous days on the system. Ive been to transation suim but I get stats on the users last logon. I require stats on a day to day basis so that I can anaylze how many users log on every day. Thank you [email prot

  • All about Point-Point Connection

    Hi All, I have read this point in the disscussion abt why we need XI 1. right now you are using point to pont connection which is not the best way. I know that the concept of ALE which is used to send the IDOC's from SAP-Non-SAP and Vice versa.This i

  • Please Clear the Difference

    Please clear the difference between these two commands Backup archive log all Backup archive log all delete input Thanks

  • Import or extract pdf file data

    Anyone have idea how to extract data or import the data from pdf file?

  • Crop confusion

    I've just set out to crop photos in an event, but even photos I haven't cropped have a crop applied to them! The crop box seems to be set to the size of the original image eg 2048x1536 (or is it the aspect ratio thereof?), but the crop box does not s