- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- using xargs and read from standard input
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 04:13 AM
01-21-2009 04:13 AM
is it possible to use command "xargs" , start a subprogramm and read in the sub programm from standard input ?
example below, it isn't possible to read from standard input in "sub programm". maybe any ideas to fix it ? command "xargs" exists in many shell scripts.
main programm:
#!/usr/bin/ksh
cat xargs.lis | xargs -l -x -t ./u_xargs-test.sh
sub programm:
#!/usr/bin/ksh
echo "this is script: `basename $0`"
echo "Number. Par: $#"
echo "Parameter: $*"
echo "Input: "
read input <= isn't possible to read from standard input
echo $input
regards,tom
Solved! Go to Solution.
- Tags:
- xargs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 04:16 AM
01-21-2009 04:16 AM
Re: using xargs and read from standard input
parameter1
parameter1 parameter2
parameter1 parameter2 parameter3
i called "main programm" : h_xargs-test.sh,
"sub programm" u_xargs-test.sh
regards,tom
regards,tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 04:54 AM
01-21-2009 04:54 AM
SolutionOne way is to change your subprogram to specifically associate STDIN with '/dev/tty' as:
#usr/bin/ksh
exec 0< /dev/tty # NOTE!
echo "this is script: `basename $0`"
echo "Number. Par: $#"
echo "Parameter: $*"
echo "Input: "
read input
echo $input
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 06:17 AM
01-21-2009 06:17 AM
Re: using xargs and read from standard input
besides JRF's solution, you can see it clearly, that such reading of stdin will not work plain, when you look on this equivalent form of your command:
xargs -l -x -t ./u_xargs-test.sh
Stdin is already redirected.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 06:30 AM
01-21-2009 06:30 AM
Re: using xargs and read from standard input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2011 06:38 AM
02-28-2011 06:38 AM
Re: using xargs and read from standard input
i have a new question to this old thread:
i detect following case:
i use this statement (u_xargs-test.sh is a sub-programm):
xargs -l -x -t ./u_xargs-test.sh
when a error occurs in "./u_xargs-test.sh" or i want to stop program with "exit 1" the "loop" of xargs doesn't stop. also "set -e" in "h_xargs-test.sh" or "u_xargs-test.sh" has no impact.
how can i stop sub program , when i use the statement "xargs" ?
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2011 07:14 AM
02-28-2011 07:14 AM
Re: using xargs and read from standard input
> how can i stop sub program , when i use the statement "xargs" ?
I don't know of anyway to do this. The 'xargs' process invokes your script for bundles of '-l' size arguments --- in this case *one*. This means that a new process (your script) is instantiated for every line read from you input. Whether or not the script (process) succeeds or fails doesn't matter to 'xargs'; it merely reads another bundle of input.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2011 07:25 AM
02-28-2011 07:25 AM
Re: using xargs and read from standard input
OK, duh! If you want your invoked process to terminate the 'xargs' statement, simply issue a 'kill ${PPID}' in your script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2011 10:16 AM
02-28-2011 10:16 AM
Re: using xargs and read from standard input
You may want to check to see that your parent actually is xargs(1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2011 10:42 PM
02-28-2011 10:42 PM
Re: using xargs and read from standard input
> You may want to check to see that your parent actually is xargs(1).
xargs terminates if it receives a return code of -1 from command or if
it cannot execute command. When command is a shell program, it should
explicitly exit (see sh(1)) with an appropriate value to avoid
accidentally returning with -1.
the "loop" of xargs continues , when i try to stop the sub-shell-program like
if [ ! -d directory ]
then
echo "dir not found"
exit 1
fi
so i have to change command "xargs" to a statement like "while" , isn't it ?
it is no so easy to change those commands :
nl -ba -w1 -s" " xargs.lis | xargs -l -x -t ./u_xargs-test.sh par1
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2011 12:37 AM
03-01-2011 12:37 AM
Re: using xargs and read from standard input
> exit 1
As documented, you need: exit -1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2011 04:15 AM
03-01-2011 04:15 AM
Re: using xargs and read from standard input
i am sorry , i miss the exact meaning ...