Operating System - HP-UX
1827955 Members
2740 Online
109973 Solutions
New Discussion

how do i insert 'carriage return' in script?

 
SOLVED
Go to solution
정은혁
New Member

how do i insert 'carriage return' in script?

Sorry this should have been posted here.

I made one script file.
------------here-----------
ftp -n host_ip <<-EOF
user user_id user_pwd
cd /home/test
bin
prompt off
get test.txt
bye
EOF
---------------------------
/usr/bin/sh here
---------------------------
this processed well.
but i want to insert that in '.c source'

------------test.c--------
snprintf(cmd_str, sizeof(cmd_str),"ftp -n host_ip <<-EOF\r\nuser user_id user_pwd\r\nbinary\r\nprompt off\r\ncd /home/test\r\nget test.txt\r\nbye\r\nEOF");

execl("/usr/bin/sh","sh","-c",cmd_str,NULL);
---------------------------

compiled and execute..

printed warnings and failed to copy a file.

?Invalid command
Interactive mode off.
?Invalid command
---------------------------

plz help me..
3 REPLIES 3
Michael Tully
Honored Contributor
Solution

Re: how do i insert 'carriage return' in script?

A carriage return is normally represented by the '\' character.
Anyone for a Mutiny ?
Hein van den Heuvel
Honored Contributor

Re: how do i insert 'carriage return' in script?

Not entirely sure but I would...

1) Drop the \r in the print. Just use \n

2) Chose between
2A) creating a temp file to execute or
2b) opening a pipe to the executable and feed it commands
2c) creating a string simialr to what you do, but tell the shell echo (or print) function to feed lines into the image. A string like 'echo "user id,pwd\nprompt\n..." | ftp -n ip'.

Good luck,
Hein.
Dave Olker
Neighborhood Moderator

Re: how do i insert 'carriage return' in script?

I got your program to run by making a few modifications:

#include

main ()
{
static char cmd_str[200];

snprintf(cmd_str, sizeof(cmd_str), "ftp -v -n SYSTEM <<-EOF\nuser USER
PASSWORD\nbinary\nprompt off\ncd /home/USER\nget test.txt\nbye\nEOF", NULL);

execl("/usr/bin/sh", "sh", "-c", cmd_str, NULL);
}


I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo